Next set of additional error checks for invalid Mach-O files for the

load commands that use the MachO::routines_command and
and MachO::routines_command_64 types but are not used in llvm
libObject code but used in llvm tool code.

This includes the LC_ROUTINES and LC_ROUTINES_64
load commands.

llvm-svn: 284504
This commit is contained in:
Kevin Enderby
2016-10-18 17:54:17 +00:00
parent 688c8347c9
commit 6f69582e9b
4 changed files with 31 additions and 0 deletions

View File

@@ -837,6 +837,7 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian,
const char *SourceLoadCmd = nullptr;
const char *EntryPointLoadCmd = nullptr;
const char *EncryptLoadCmd = nullptr;
const char *RoutinesLoadCmd = nullptr;
for (unsigned I = 0; I < LoadCommandCount; ++I) {
if (is64Bit()) {
if (Load.C.cmdsize % 8 != 0) {
@@ -1064,6 +1065,30 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian,
sizeof(MachO::sub_client_command),
"sub_client_command", S.client, "client")))
return;
} else if (Load.C.cmd == MachO::LC_ROUTINES) {
if (Load.C.cmdsize != sizeof(MachO::routines_command)) {
Err = malformedError("LC_ROUTINES command " + Twine(I) +
" has incorrect cmdsize");
return;
}
if (RoutinesLoadCmd) {
Err = malformedError("more than one LC_ROUTINES and or LC_ROUTINES_64 "
"command");
return;
}
RoutinesLoadCmd = Load.Ptr;
} else if (Load.C.cmd == MachO::LC_ROUTINES_64) {
if (Load.C.cmdsize != sizeof(MachO::routines_command_64)) {
Err = malformedError("LC_ROUTINES_64 command " + Twine(I) +
" has incorrect cmdsize");
return;
}
if (RoutinesLoadCmd) {
Err = malformedError("more than one LC_ROUTINES_64 and or LC_ROUTINES "
"command");
return;
}
RoutinesLoadCmd = Load.Ptr;
}
if (I < LoadCommandCount - 1) {
if (auto LoadOrErr = getNextLoadCommandInfo(this, I, Load))