Add checks to the MachOObjectFile() constructor to make sure load commands sizes

are the correct multiple.

llvm-svn: 274798
This commit is contained in:
Kevin Enderby 2016-07-07 22:11:42 +00:00
parent a1a36c85df
commit 1851a827a0
2 changed files with 25 additions and 3 deletions

View File

@ -297,6 +297,25 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian,
}
for (unsigned I = 0; I < LoadCommandCount; ++I) {
if (is64Bit()) {
if (Load.C.cmdsize % 8 != 0) {
// We have a hack here to allow 64-bit Mach-O core files to have
// LC_THREAD commands that are only a multiple of 4 and not 8 to be
// allowed since the macOS kernel produces them.
if (getHeader().filetype != MachO::MH_CORE ||
Load.C.cmd != MachO::LC_THREAD || Load.C.cmdsize % 4) {
Err = malformedError("load command " + Twine(I) + " cmdsize not a "
"multiple of 8");
return;
}
}
} else {
if (Load.C.cmdsize % 4 != 0) {
Err = malformedError("load command " + Twine(I) + " cmdsize not a "
"multiple of 4");
return;
}
}
LoadCommands.push_back(Load);
if (Load.C.cmd == MachO::LC_SYMTAB) {
// Multiple symbol tables

View File

@ -24,13 +24,16 @@ RUN: | FileCheck -check-prefix SMALL-LOADC-SIZE-1 %s
SMALL-LOADC-SIZE-1: truncated or malformed object (load command 1 with size less than 8 bytes)
RUN: not llvm-objdump -private-headers %p/Inputs/macho-invalid-too-small-segment-load-command 2>&1 \
RUN: | FileCheck -check-prefix SMALL-SEGLOADC-SIZE %s
RUN: | FileCheck -check-prefix MULTIPLE-NOT-4 %s
MULTIPLE-NOT-4: truncated or malformed object (load command 0 cmdsize not a multiple of 4)
RUN: not llvm-objdump -private-headers %p/Inputs/macho-invalid-too-small-segment-load-command.1 2>&1 \
RUN: | FileCheck -check-prefix SMALL-SEGLOADC-SIZE %s
SMALL-SEGLOADC-SIZE: truncated or malformed object (load command 0 LC_SEGMENT cmdsize too small)
RUN: not llvm-objdump -private-headers %p/Inputs/macho64-invalid-too-small-segment-load-command 2>&1 \
RUN: | FileCheck -check-prefix SMALL-SEGLOADC-SIZE-64 %s
SMALL-SEGLOADC-SIZE-64: truncated or malformed object (load command 0 LC_SEGMENT_64 cmdsize too small)
RUN: | FileCheck -check-prefix MULTIPLE-NOT-8 %s
MULTIPLE-NOT-8: truncated or malformed object (load command 0 cmdsize not a multiple of 8)
RUN: not llvm-objdump -private-headers %p/Inputs/macho-invalid-no-size-for-sections 2>&1 \
RUN: | FileCheck -check-prefix TOO-MANY-SECTS %s