[llvm] r274798 - Add checks to the MachOObjectFile() constructor to make sure load commands sizes
Kevin Enderby via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 7 15:11:42 PDT 2016
Author: enderby
Date: Thu Jul 7 17:11:42 2016
New Revision: 274798
URL: http://llvm.org/viewvc/llvm-project?rev=274798&view=rev
Log:
Add checks to the MachOObjectFile() constructor to make sure load commands sizes
are the correct multiple.
Modified:
llvm/trunk/lib/Object/MachOObjectFile.cpp
llvm/trunk/test/Object/macho-invalid.test
Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=274798&r1=274797&r2=274798&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Thu Jul 7 17:11:42 2016
@@ -297,6 +297,25 @@ MachOObjectFile::MachOObjectFile(MemoryB
}
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
Modified: llvm/trunk/test/Object/macho-invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/macho-invalid.test?rev=274798&r1=274797&r2=274798&view=diff
==============================================================================
--- llvm/trunk/test/Object/macho-invalid.test (original)
+++ llvm/trunk/test/Object/macho-invalid.test Thu Jul 7 17:11:42 2016
@@ -24,13 +24,16 @@ RUN: | FileCheck -check-prefix SMAL
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
More information about the llvm-commits
mailing list