[mach-o] Add checks that string literals in object files are zero terminated
authorNick Kledzik <kledzik@apple.com>
Tue, 27 May 2014 20:37:08 +0000 (20:37 +0000)
committerNick Kledzik <kledzik@apple.com>
Tue, 27 May 2014 20:37:08 +0000 (20:37 +0000)
llvm-svn: 209685

lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp

index 7564748..69ff193 100644 (file)
@@ -129,6 +129,14 @@ static error_code processSection(MachOFile &file, const Section &section,
           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(MachOFile &file, const Section &section,
         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)