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

llvm-svn: 209685
This commit is contained in:
Nick Kledzik 2014-05-27 20:37:08 +00:00
parent 3e90e5f187
commit 81e105e8d6
1 changed files with 15 additions and 0 deletions

View 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)