From 89baf99c924bcb484339c2b06d49cfc1b63df761 Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Tue, 18 Oct 2016 20:24:12 +0000 Subject: [PATCH] One more additional error check for invalid Mach-O files for a 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. llvm-svn: 284529 --- llvm/lib/Object/MachOObjectFile.cpp | 5 +++++ llvm/test/Object/Inputs/macho-invalid-codesign-bad-size | Bin 0 -> 48 bytes llvm/test/Object/macho-invalid.test | 3 +++ 3 files changed, 8 insertions(+) create mode 100644 llvm/test/Object/Inputs/macho-invalid-codesign-bad-size diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index c0d7d83..a6cdc288 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/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/llvm/test/Object/Inputs/macho-invalid-codesign-bad-size b/llvm/test/Object/Inputs/macho-invalid-codesign-bad-size new file mode 100644 index 0000000000000000000000000000000000000000..661ac116426c6ce029c5945219d28e082a9085dd GIT binary patch literal 48 gcmX^2>+L^w1_lOZAZCPO5g-i$vOo-Dg9U&D0JD|^1poj5 literal 0 HcmV?d00001 diff --git a/llvm/test/Object/macho-invalid.test b/llvm/test/Object/macho-invalid.test index 8b33149..cde4520 100644 --- a/llvm/test/Object/macho-invalid.test +++ b/llvm/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) -- 2.7.4