Skip to content

Commit

Permalink
One more additional error check for invalid Mach-O files for a
Browse files Browse the repository at this point in the history
load command that use the MachO:: linkedit_data_command
type but is not used in llvm libObject code but used in llvm tool code.

This is for the LC_CODE_SIGNATURE load command.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284529 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
enderby committed Oct 18, 2016
1 parent 55352d9 commit c6b8aca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Object/MachOObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian,
const char *FuncStartsLoadCmd = nullptr;
const char *SplitInfoLoadCmd = nullptr;
const char *CodeSignDrsLoadCmd = nullptr;
const char *CodeSignLoadCmd = nullptr;
const char *VersLoadCmd = nullptr;
const char *SourceLoadCmd = nullptr;
const char *EntryPointLoadCmd = nullptr;
Expand Down Expand Up @@ -885,6 +886,10 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian,
if ((Err = checkLinkeditDataCommand(this, Load, I, &CodeSignDrsLoadCmd,
"LC_DYLIB_CODE_SIGN_DRS")))
return;
} else if (Load.C.cmd == MachO::LC_CODE_SIGNATURE) {
if ((Err = checkLinkeditDataCommand(this, Load, I, &CodeSignLoadCmd,
"LC_CODE_SIGNATURE")))
return;
} else if (Load.C.cmd == MachO::LC_DYLD_INFO) {
if ((Err = checkDyldInfoCommand(this, Load, I, &DyldInfoLoadCmd,
"LC_DYLD_INFO")))
Expand Down
Binary file added test/Object/Inputs/macho-invalid-codesign-bad-size
Binary file not shown.
3 changes: 3 additions & 0 deletions test/Object/macho-invalid.test
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,6 @@ INVALID-ROUTINES-BAD-SIZE: macho-invalid-routines-bad-size': truncated or malfor

RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-routines64-more-than-one 2>&1 | FileCheck -check-prefix INVALID-ROUTINES64-MORE-THAN-ONE %s
INVALID-ROUTINES64-MORE-THAN-ONE: macho-invalid-routines64-more-than-one': truncated or malformed object (more than one LC_ROUTINES_64 and or LC_ROUTINES command)

RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-codesign-bad-size 2>&1 | FileCheck -check-prefix INVALID-CODESIGN-BAD-SIZE %s
INVALID-CODESIGN-BAD-SIZE: macho-invalid-codesign-bad-size': truncated or malformed object (LC_CODE_SIGNATURE command 0 has incorrect cmdsize)

0 comments on commit c6b8aca

Please sign in to comment.