diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index c0d7d83d08e..a6cdc288431 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -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; @@ -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"))) diff --git a/test/Object/Inputs/macho-invalid-codesign-bad-size b/test/Object/Inputs/macho-invalid-codesign-bad-size new file mode 100644 index 00000000000..661ac116426 Binary files /dev/null and b/test/Object/Inputs/macho-invalid-codesign-bad-size differ diff --git a/test/Object/macho-invalid.test b/test/Object/macho-invalid.test index 8b33149bb80..cde45206823 100644 --- a/test/Object/macho-invalid.test +++ b/test/Object/macho-invalid.test @@ -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)