llvm.org GIT mirror llvm / ac3d934
Add checks to the MachOObjectFile() constructor to make sure load commands sizes are the correct multiple. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274798 91177308-0d34-0410-b5e6-96231b3b80d8 Kevin Enderby 3 years ago
2 changed file(s) with 25 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
296296 }
297297
298298 for (unsigned I = 0; I < LoadCommandCount; ++I) {
299 if (is64Bit()) {
300 if (Load.C.cmdsize % 8 != 0) {
301 // We have a hack here to allow 64-bit Mach-O core files to have
302 // LC_THREAD commands that are only a multiple of 4 and not 8 to be
303 // allowed since the macOS kernel produces them.
304 if (getHeader().filetype != MachO::MH_CORE ||
305 Load.C.cmd != MachO::LC_THREAD || Load.C.cmdsize % 4) {
306 Err = malformedError("load command " + Twine(I) + " cmdsize not a "
307 "multiple of 8");
308 return;
309 }
310 }
311 } else {
312 if (Load.C.cmdsize % 4 != 0) {
313 Err = malformedError("load command " + Twine(I) + " cmdsize not a "
314 "multiple of 4");
315 return;
316 }
317 }
299318 LoadCommands.push_back(Load);
300319 if (Load.C.cmd == MachO::LC_SYMTAB) {
301320 // Multiple symbol tables
2323 SMALL-LOADC-SIZE-1: truncated or malformed object (load command 1 with size less than 8 bytes)
2424
2525 RUN: not llvm-objdump -private-headers %p/Inputs/macho-invalid-too-small-segment-load-command 2>&1 \
26 RUN: | FileCheck -check-prefix SMALL-SEGLOADC-SIZE %s
26 RUN: | FileCheck -check-prefix MULTIPLE-NOT-4 %s
27 MULTIPLE-NOT-4: truncated or malformed object (load command 0 cmdsize not a multiple of 4)
28
2729 RUN: not llvm-objdump -private-headers %p/Inputs/macho-invalid-too-small-segment-load-command.1 2>&1 \
2830 RUN: | FileCheck -check-prefix SMALL-SEGLOADC-SIZE %s
2931 SMALL-SEGLOADC-SIZE: truncated or malformed object (load command 0 LC_SEGMENT cmdsize too small)
32
3033 RUN: not llvm-objdump -private-headers %p/Inputs/macho64-invalid-too-small-segment-load-command 2>&1 \
31 RUN: | FileCheck -check-prefix SMALL-SEGLOADC-SIZE-64 %s
32 SMALL-SEGLOADC-SIZE-64: truncated or malformed object (load command 0 LC_SEGMENT_64 cmdsize too small)
34 RUN: | FileCheck -check-prefix MULTIPLE-NOT-8 %s
35 MULTIPLE-NOT-8: truncated or malformed object (load command 0 cmdsize not a multiple of 8)
3336
3437 RUN: not llvm-objdump -private-headers %p/Inputs/macho-invalid-no-size-for-sections 2>&1 \
3538 RUN: | FileCheck -check-prefix TOO-MANY-SECTS %s