[lld] r209685 - [mach-o] Add checks that string literals in object files are zero terminated

Nick Kledzik kledzik at apple.com
Tue May 27 13:37:08 PDT 2014


Author: kledzik
Date: Tue May 27 15:37:08 2014
New Revision: 209685

URL: http://llvm.org/viewvc/llvm-project?rev=209685&view=rev
Log:
[mach-o] Add checks that string literals in object files are zero terminated

Modified:
    lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp

Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp?rev=209685&r1=209684&r2=209685&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp Tue May 27 15:37:08 2014
@@ -129,6 +129,14 @@ static error_code processSection(MachOFi
           offset = i + 2;
         }
       }
+      if (offset != section.content.size()) {
+        return make_dynamic_error_code(Twine("Section ") + section.segmentName
+                                       + "/" + section.sectionName 
+                                       + " is supposed to contain 0x0000 "
+                                       "terminated UTF16 strings, but the "
+                                       "last string in the section is not zero "
+                                       "terminated."); 
+      }
     }
   case llvm::MachO::S_COALESCED:
   case llvm::MachO::S_ZEROFILL:
@@ -144,6 +152,13 @@ static error_code processSection(MachOFi
         offset = i + 1;
       }
     }
+    if (offset != section.content.size()) {
+      return make_dynamic_error_code(Twine("Section ") + section.segmentName
+                                     + "/" + section.sectionName 
+                                     + " has type S_CSTRING_LITERALS but the "
+                                     "last string in the section is not zero "
+                                     "terminated."); 
+    }
     break;
   case llvm::MachO::S_4BYTE_LITERALS:
     if ((section.content.size() % 4) != 0)





More information about the llvm-commits mailing list