From: Kevin Enderby Date: Wed, 2 Nov 2016 21:08:39 +0000 (+0000) Subject: Add the rest of the additional error checks for invalid Mach-O files when X-Git-Tag: llvmorg-4.0.0-rc1~5589 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fbebe1632aaa0f5cc52a4d902cc80eb9b97efa6a;p=platform%2Fupstream%2Fllvm.git Add the rest of the additional error checks for invalid Mach-O files when the offsets and sizes of an element of the Mach-O file overlaps with another element in the Mach-O file. Some other tests for malformed Mach-O files now run into these checks so their tests were also adjusted. llvm-svn: 285860 --- diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index 724056f..3aec182 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -260,7 +260,8 @@ template static Error parseSegmentLoadCommand( const MachOObjectFile *Obj, const MachOObjectFile::LoadCommandInfo &Load, SmallVectorImpl &Sections, bool &IsPageZeroSegment, - uint32_t LoadCommandIndex, const char *CmdName, uint64_t SizeOfHeaders) { + uint32_t LoadCommandIndex, const char *CmdName, uint64_t SizeOfHeaders, + std::list &Elements) { const unsigned SegmentLoadSize = sizeof(Segment); if (Load.C.cmdsize < SegmentLoadSize) return malformedError("load command " + Twine(LoadCommandIndex) + @@ -330,6 +331,13 @@ static Error parseSegmentLoadCommand( Twine(LoadCommandIndex) + " greater than than " "the segment's vmaddr plus vmsize"); + if (Obj->getHeader().filetype != MachO::MH_DYLIB_STUB && + Obj->getHeader().filetype != MachO::MH_DSYM && + s.flags != MachO::S_ZEROFILL && + s.flags != MachO::S_THREAD_LOCAL_ZEROFILL) + if (Error Err = checkOverlappingElement(Elements, s.offset, s.size, + "section contents")) + return Err; if (s.reloff > FileSize) return malformedError("reloff field of section " + Twine(J) + " in " + CmdName + " command " + Twine(LoadCommandIndex) + @@ -343,6 +351,11 @@ static Error parseSegmentLoadCommand( Twine(J) + " in " + CmdName + " command " + Twine(LoadCommandIndex) + " extends past the end of the file"); + if (Error Err = checkOverlappingElement(Elements, s.reloff, s.nreloc * + sizeof(struct + MachO::relocation_info), + "section relocation entries")) + return Err; } if (S.fileoff > FileSize) return malformedError("load command " + Twine(LoadCommandIndex) + @@ -424,7 +437,8 @@ static Error checkSymtabCommand(const MachOObjectFile *Obj, static Error checkDysymtabCommand(const MachOObjectFile *Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, - const char **DysymtabLoadCmd) { + const char **DysymtabLoadCmd, + std::list &Elements) { if (Load.C.cmdsize < sizeof(MachO::dysymtab_command)) return malformedError("load command " + Twine(LoadCommandIndex) + " LC_DYSYMTAB cmdsize too small"); @@ -448,25 +462,36 @@ static Error checkDysymtabCommand(const MachOObjectFile *Obj, "dylib_table_of_contents) of LC_DYSYMTAB command " + Twine(LoadCommandIndex) + " extends past the end of " "the file"); + if (Error Err = checkOverlappingElement(Elements, Dysymtab.tocoff, + Dysymtab.ntoc * sizeof(struct + MachO::dylib_table_of_contents), + "table of contents")) + return Err; if (Dysymtab.modtaboff > FileSize) return malformedError("modtaboff field of LC_DYSYMTAB command " + Twine(LoadCommandIndex) + " extends past the end of " "the file"); BigSize = Dysymtab.nmodtab; const char *struct_dylib_module_name; + uint64_t sizeof_modtab; if (Obj->is64Bit()) { - BigSize *= sizeof(MachO::dylib_module_64); + sizeof_modtab = sizeof(MachO::dylib_module_64); struct_dylib_module_name = "struct dylib_module_64"; } else { - BigSize *= sizeof(MachO::dylib_module); + sizeof_modtab = sizeof(MachO::dylib_module); struct_dylib_module_name = "struct dylib_module"; } + BigSize *= sizeof_modtab; BigSize += Dysymtab.modtaboff; if (BigSize > FileSize) return malformedError("modtaboff field plus nmodtab field times sizeof(" + Twine(struct_dylib_module_name) + ") of LC_DYSYMTAB " "command " + Twine(LoadCommandIndex) + " extends " "past the end of the file"); + if (Error Err = checkOverlappingElement(Elements, Dysymtab.modtaboff, + Dysymtab.nmodtab * sizeof_modtab, + "module table")) + return Err; if (Dysymtab.extrefsymoff > FileSize) return malformedError("extrefsymoff field of LC_DYSYMTAB command " + Twine(LoadCommandIndex) + " extends past the end of " @@ -479,6 +504,11 @@ static Error checkDysymtabCommand(const MachOObjectFile *Obj, "sizeof(struct dylib_reference) of LC_DYSYMTAB " "command " + Twine(LoadCommandIndex) + " extends " "past the end of the file"); + if (Error Err = checkOverlappingElement(Elements, Dysymtab.extrefsymoff, + Dysymtab.nextrefsyms * + sizeof(MachO::dylib_reference), + "reference table")) + return Err; if (Dysymtab.indirectsymoff > FileSize) return malformedError("indirectsymoff field of LC_DYSYMTAB command " + Twine(LoadCommandIndex) + " extends past the end of " @@ -491,6 +521,11 @@ static Error checkDysymtabCommand(const MachOObjectFile *Obj, "sizeof(uint32_t) of LC_DYSYMTAB command " + Twine(LoadCommandIndex) + " extends past the end of " "the file"); + if (Error Err = checkOverlappingElement(Elements, Dysymtab.indirectsymoff, + Dysymtab.nindirectsyms * + sizeof(uint32_t), + "indirect table")) + return Err; if (Dysymtab.extreloff > FileSize) return malformedError("extreloff field of LC_DYSYMTAB command " + Twine(LoadCommandIndex) + " extends past the end of " @@ -503,6 +538,11 @@ static Error checkDysymtabCommand(const MachOObjectFile *Obj, "(struct relocation_info) of LC_DYSYMTAB command " + Twine(LoadCommandIndex) + " extends past the end of " "the file"); + if (Error Err = checkOverlappingElement(Elements, Dysymtab.extreloff, + Dysymtab.nextrel * + sizeof(MachO::relocation_info), + "external relocation table")) + return Err; if (Dysymtab.locreloff > FileSize) return malformedError("locreloff field of LC_DYSYMTAB command " + Twine(LoadCommandIndex) + " extends past the end of " @@ -515,6 +555,11 @@ static Error checkDysymtabCommand(const MachOObjectFile *Obj, "(struct relocation_info) of LC_DYSYMTAB command " + Twine(LoadCommandIndex) + " extends past the end of " "the file"); + if (Error Err = checkOverlappingElement(Elements, Dysymtab.locreloff, + Dysymtab.nlocrel * + sizeof(MachO::relocation_info), + "local relocation table")) + return Err; *DysymtabLoadCmd = Load.Ptr; return Error::success(); } @@ -522,7 +567,9 @@ static Error checkDysymtabCommand(const MachOObjectFile *Obj, static Error checkLinkeditDataCommand(const MachOObjectFile *Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, - const char **LoadCmd, const char *CmdName) { + const char **LoadCmd, const char *CmdName, + std::list &Elements, + const char *ElementName) { if (Load.C.cmdsize < sizeof(MachO::linkedit_data_command)) return malformedError("load command " + Twine(LoadCommandIndex) + " " + CmdName + " cmdsize too small"); @@ -545,6 +592,9 @@ static Error checkLinkeditDataCommand(const MachOObjectFile *Obj, Twine(CmdName) + " command " + Twine(LoadCommandIndex) + " extends past the end of " "the file"); + if (Error Err = checkOverlappingElement(Elements, LinkData.dataoff, + LinkData.datasize, ElementName)) + return Err; *LoadCmd = Load.Ptr; return Error::success(); } @@ -552,7 +602,8 @@ static Error checkLinkeditDataCommand(const MachOObjectFile *Obj, static Error checkDyldInfoCommand(const MachOObjectFile *Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, - const char **LoadCmd, const char *CmdName) { + const char **LoadCmd, const char *CmdName, + std::list &Elements) { if (Load.C.cmdsize < sizeof(MachO::dyld_info_command)) return malformedError("load command " + Twine(LoadCommandIndex) + " " + CmdName + " cmdsize too small"); @@ -576,6 +627,10 @@ static Error checkDyldInfoCommand(const MachOObjectFile *Obj, Twine(CmdName) + " command " + Twine(LoadCommandIndex) + " extends past the end of " "the file"); + if (Error Err = checkOverlappingElement(Elements, DyldInfo.rebase_off, + DyldInfo.rebase_size, + "dyld rebase info")) + return Err; if (DyldInfo.bind_off > FileSize) return malformedError("bind_off field of " + Twine(CmdName) + " command " + Twine(LoadCommandIndex) + " extends " @@ -587,6 +642,10 @@ static Error checkDyldInfoCommand(const MachOObjectFile *Obj, Twine(CmdName) + " command " + Twine(LoadCommandIndex) + " extends past the end of " "the file"); + if (Error Err = checkOverlappingElement(Elements, DyldInfo.bind_off, + DyldInfo.bind_size, + "dyld bind info")) + return Err; if (DyldInfo.weak_bind_off > FileSize) return malformedError("weak_bind_off field of " + Twine(CmdName) + " command " + Twine(LoadCommandIndex) + " extends " @@ -598,6 +657,10 @@ static Error checkDyldInfoCommand(const MachOObjectFile *Obj, Twine(CmdName) + " command " + Twine(LoadCommandIndex) + " extends past the end of " "the file"); + if (Error Err = checkOverlappingElement(Elements, DyldInfo.weak_bind_off, + DyldInfo.weak_bind_size, + "dyld weak bind info")) + return Err; if (DyldInfo.lazy_bind_off > FileSize) return malformedError("lazy_bind_off field of " + Twine(CmdName) + " command " + Twine(LoadCommandIndex) + " extends " @@ -609,6 +672,10 @@ static Error checkDyldInfoCommand(const MachOObjectFile *Obj, Twine(CmdName) + " command " + Twine(LoadCommandIndex) + " extends past the end of " "the file"); + if (Error Err = checkOverlappingElement(Elements, DyldInfo.lazy_bind_off, + DyldInfo.lazy_bind_size, + "dyld lazy bind info")) + return Err; if (DyldInfo.export_off > FileSize) return malformedError("export_off field of " + Twine(CmdName) + " command " + Twine(LoadCommandIndex) + " extends " @@ -620,6 +687,10 @@ static Error checkDyldInfoCommand(const MachOObjectFile *Obj, Twine(CmdName) + " command " + Twine(LoadCommandIndex) + " extends past the end of " "the file"); + if (Error Err = checkOverlappingElement(Elements, DyldInfo.export_off, + DyldInfo.export_size, + "dyld export info")) + return Err; *LoadCmd = Load.Ptr; return Error::success(); } @@ -932,7 +1003,8 @@ static Error checkTwoLevelHintsCommand(const MachOObjectFile *Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, - const char **LoadCmd) { + const char **LoadCmd, + std::list &Elements) { if (Load.C.cmdsize != sizeof(MachO::twolevel_hints_command)) return malformedError("load command " + Twine(LoadCommandIndex) + " LC_TWOLEVEL_HINTS has incorrect cmdsize"); @@ -953,6 +1025,10 @@ static Error checkTwoLevelHintsCommand(const MachOObjectFile *Obj, "twolevel_hint) field of LC_TWOLEVEL_HINTS command " + Twine(LoadCommandIndex) + " extends past the end of " "the file"); + if (Error Err = checkOverlappingElement(Elements, Hints.offset, Hints.nhints * + sizeof(MachO::twolevel_hint), + "two level hints")) + return Err; *LoadCmd = Load.Ptr; return Error::success(); } @@ -1073,39 +1149,47 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian, if ((Err = checkSymtabCommand(this, Load, I, &SymtabLoadCmd, Elements))) return; } else if (Load.C.cmd == MachO::LC_DYSYMTAB) { - if ((Err = checkDysymtabCommand(this, Load, I, &DysymtabLoadCmd))) + if ((Err = checkDysymtabCommand(this, Load, I, &DysymtabLoadCmd, + Elements))) return; } else if (Load.C.cmd == MachO::LC_DATA_IN_CODE) { if ((Err = checkLinkeditDataCommand(this, Load, I, &DataInCodeLoadCmd, - "LC_DATA_IN_CODE"))) + "LC_DATA_IN_CODE", Elements, + "data in code info"))) return; } else if (Load.C.cmd == MachO::LC_LINKER_OPTIMIZATION_HINT) { if ((Err = checkLinkeditDataCommand(this, Load, I, &LinkOptHintsLoadCmd, - "LC_LINKER_OPTIMIZATION_HINT"))) + "LC_LINKER_OPTIMIZATION_HINT", + Elements, "linker optimization " + "hints"))) return; } else if (Load.C.cmd == MachO::LC_FUNCTION_STARTS) { if ((Err = checkLinkeditDataCommand(this, Load, I, &FuncStartsLoadCmd, - "LC_FUNCTION_STARTS"))) + "LC_FUNCTION_STARTS", Elements, + "function starts data"))) return; } else if (Load.C.cmd == MachO::LC_SEGMENT_SPLIT_INFO) { if ((Err = checkLinkeditDataCommand(this, Load, I, &SplitInfoLoadCmd, - "LC_SEGMENT_SPLIT_INFO"))) + "LC_SEGMENT_SPLIT_INFO", Elements, + "split info data"))) return; } else if (Load.C.cmd == MachO::LC_DYLIB_CODE_SIGN_DRS) { if ((Err = checkLinkeditDataCommand(this, Load, I, &CodeSignDrsLoadCmd, - "LC_DYLIB_CODE_SIGN_DRS"))) + "LC_DYLIB_CODE_SIGN_DRS", Elements, + "code signing RDs data"))) return; } else if (Load.C.cmd == MachO::LC_CODE_SIGNATURE) { if ((Err = checkLinkeditDataCommand(this, Load, I, &CodeSignLoadCmd, - "LC_CODE_SIGNATURE"))) + "LC_CODE_SIGNATURE", Elements, + "code signature data"))) return; } else if (Load.C.cmd == MachO::LC_DYLD_INFO) { if ((Err = checkDyldInfoCommand(this, Load, I, &DyldInfoLoadCmd, - "LC_DYLD_INFO"))) + "LC_DYLD_INFO", Elements))) return; } else if (Load.C.cmd == MachO::LC_DYLD_INFO_ONLY) { if ((Err = checkDyldInfoCommand(this, Load, I, &DyldInfoLoadCmd, - "LC_DYLD_INFO_ONLY"))) + "LC_DYLD_INFO_ONLY", Elements))) return; } else if (Load.C.cmd == MachO::LC_UUID) { if (Load.C.cmdsize != sizeof(MachO::uuid_command)) { @@ -1122,13 +1206,13 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian, if ((Err = parseSegmentLoadCommand( this, Load, Sections, HasPageZeroSegment, I, - "LC_SEGMENT_64", SizeOfHeaders))) + "LC_SEGMENT_64", SizeOfHeaders, Elements))) return; } else if (Load.C.cmd == MachO::LC_SEGMENT) { if ((Err = parseSegmentLoadCommand( this, Load, Sections, HasPageZeroSegment, I, - "LC_SEGMENT", SizeOfHeaders))) + "LC_SEGMENT", SizeOfHeaders, Elements))) return; } else if (Load.C.cmd == MachO::LC_ID_DYLIB) { if ((Err = checkDylibIdCommand(this, Load, I, &DyldIdLoadCmd))) @@ -1317,7 +1401,7 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian, // Note: LC_TWOLEVEL_HINTS is really obsolete and is not supported. } else if (Load.C.cmd == MachO::LC_TWOLEVEL_HINTS) { if ((Err = checkTwoLevelHintsCommand(this, Load, I, - &TwoLevelHintsLoadCmd))) + &TwoLevelHintsLoadCmd, Elements))) return; } else if (isLoadCommandObsolete(Load.C.cmd)) { Err = malformedError("load command " + Twine(I) + " for cmd value of: " + diff --git a/llvm/test/Object/Inputs/macho-invalid-bind-overlap b/llvm/test/Object/Inputs/macho-invalid-bind-overlap new file mode 100644 index 0000000..206315c Binary files /dev/null and b/llvm/test/Object/Inputs/macho-invalid-bind-overlap differ diff --git a/llvm/test/Object/Inputs/macho-invalid-codesig-overlap b/llvm/test/Object/Inputs/macho-invalid-codesig-overlap new file mode 100644 index 0000000..a989bad Binary files /dev/null and b/llvm/test/Object/Inputs/macho-invalid-codesig-overlap differ diff --git a/llvm/test/Object/Inputs/macho-invalid-export-overlap b/llvm/test/Object/Inputs/macho-invalid-export-overlap new file mode 100644 index 0000000..2931918 Binary files /dev/null and b/llvm/test/Object/Inputs/macho-invalid-export-overlap differ diff --git a/llvm/test/Object/Inputs/macho-invalid-extrefsyms-overlap b/llvm/test/Object/Inputs/macho-invalid-extrefsyms-overlap new file mode 100644 index 0000000..5778f67 Binary files /dev/null and b/llvm/test/Object/Inputs/macho-invalid-extrefsyms-overlap differ diff --git a/llvm/test/Object/Inputs/macho-invalid-extreloff-overlap b/llvm/test/Object/Inputs/macho-invalid-extreloff-overlap new file mode 100644 index 0000000..2226556 Binary files /dev/null and b/llvm/test/Object/Inputs/macho-invalid-extreloff-overlap differ diff --git a/llvm/test/Object/Inputs/macho-invalid-hints-overlap b/llvm/test/Object/Inputs/macho-invalid-hints-overlap new file mode 100644 index 0000000..87a62b8 Binary files /dev/null and b/llvm/test/Object/Inputs/macho-invalid-hints-overlap differ diff --git a/llvm/test/Object/Inputs/macho-invalid-indirectsyms-overlap b/llvm/test/Object/Inputs/macho-invalid-indirectsyms-overlap new file mode 100644 index 0000000..f974864 Binary files /dev/null and b/llvm/test/Object/Inputs/macho-invalid-indirectsyms-overlap differ diff --git a/llvm/test/Object/Inputs/macho-invalid-lazy_bind-overlap b/llvm/test/Object/Inputs/macho-invalid-lazy_bind-overlap new file mode 100644 index 0000000..9905305 Binary files /dev/null and b/llvm/test/Object/Inputs/macho-invalid-lazy_bind-overlap differ diff --git a/llvm/test/Object/Inputs/macho-invalid-locreloff-overlap b/llvm/test/Object/Inputs/macho-invalid-locreloff-overlap new file mode 100644 index 0000000..be25c79 Binary files /dev/null and b/llvm/test/Object/Inputs/macho-invalid-locreloff-overlap differ diff --git a/llvm/test/Object/Inputs/macho-invalid-modtab-overlap b/llvm/test/Object/Inputs/macho-invalid-modtab-overlap new file mode 100644 index 0000000..4ee023c Binary files /dev/null and b/llvm/test/Object/Inputs/macho-invalid-modtab-overlap differ diff --git a/llvm/test/Object/Inputs/macho-invalid-rebase-overlap b/llvm/test/Object/Inputs/macho-invalid-rebase-overlap new file mode 100644 index 0000000..267afd6 Binary files /dev/null and b/llvm/test/Object/Inputs/macho-invalid-rebase-overlap differ diff --git a/llvm/test/Object/Inputs/macho-invalid-reloc-overlap b/llvm/test/Object/Inputs/macho-invalid-reloc-overlap new file mode 100644 index 0000000..98fe322 Binary files /dev/null and b/llvm/test/Object/Inputs/macho-invalid-reloc-overlap differ diff --git a/llvm/test/Object/Inputs/macho-invalid-section-overlap b/llvm/test/Object/Inputs/macho-invalid-section-overlap new file mode 100644 index 0000000..ab3f4fb Binary files /dev/null and b/llvm/test/Object/Inputs/macho-invalid-section-overlap differ diff --git a/llvm/test/Object/Inputs/macho-invalid-toc-overlap b/llvm/test/Object/Inputs/macho-invalid-toc-overlap new file mode 100644 index 0000000..a3afa58 Binary files /dev/null and b/llvm/test/Object/Inputs/macho-invalid-toc-overlap differ diff --git a/llvm/test/Object/Inputs/macho-invalid-weak_bind-overlap b/llvm/test/Object/Inputs/macho-invalid-weak_bind-overlap new file mode 100644 index 0000000..ce1f3e0 Binary files /dev/null and b/llvm/test/Object/Inputs/macho-invalid-weak_bind-overlap differ diff --git a/llvm/test/Object/macho-invalid.test b/llvm/test/Object/macho-invalid.test index 105bfb0..b193ebb 100644 --- a/llvm/test/Object/macho-invalid.test +++ b/llvm/test/Object/macho-invalid.test @@ -439,3 +439,48 @@ INVALID-SYMTAB-OVERLAP: macho-invalid-symtab-overlap': truncated or malformed ob RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-strtab-overlap 2>&1 | FileCheck -check-prefix INVALID-STRTAB-OVERLAP %s INVALID-STRTAB-OVERLAP: macho-invalid-strtab-overlap': truncated or malformed object (string table at offset 60 with a size of 16, overlaps symbol table at offset 52 with a size of 12) + +RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-section-overlap 2>&1 | FileCheck -check-prefix INVALID-SECTION-OVERLAP %s +INVALID-SECTION-OVERLAP: macho-invalid-section-overlap': truncated or malformed object (symbol table at offset 208 with a size of 12, overlaps section contents at offset 184 with a size of 32) + +RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-reloc-overlap 2>&1 | FileCheck -check-prefix INVALID-RELOC-OVERLAP %s +INVALID-RELOC-OVERLAP: macho-invalid-reloc-overlap': truncated or malformed object (section relocation entries at offset 204 with a size of 8, overlaps section contents at offset 176 with a size of 32) + +RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-toc-overlap 2>&1 | FileCheck -check-prefix INVALID-TOC-OVERLAP %s +INVALID-TOC-OVERLAP: macho-invalid-toc-overlap': truncated or malformed object (table of contents at offset 292 with a size of 8, overlaps section relocation entries at offset 288 with a size of 8) + +RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-modtab-overlap 2>&1 | FileCheck -check-prefix INVALID-MODTAB-OVERLAP %s +INVALID-MODTAB-OVERLAP: macho-invalid-modtab-overlap': truncated or malformed object (module table at offset 300 with a size of 52, overlaps table of contents at offset 296 with a size of 8) + +RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-extrefsyms-overlap 2>&1 | FileCheck -check-prefix INVALID-EXTREFSYMS-OVERLAP %s +INVALID-EXTREFSYMS-OVERLAP: macho-invalid-extrefsyms-overlap': truncated or malformed object (reference table at offset 352 with a size of 4, overlaps module table at offset 304 with a size of 52) + +RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-indirectsyms-overlap 2>&1 | FileCheck -check-prefix INVALID-INDIRECTSYMS-OVERLAP %s +INVALID-INDIRECTSYMS-OVERLAP: macho-invalid-indirectsyms-overlap': truncated or malformed object (indirect table at offset 364 with a size of 4, overlaps section contents at offset 364 with a size of 4) + +RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-extreloff-overlap 2>&1 | FileCheck -check-prefix INVALID-EXTRELOFF-OVERLAP %s +INVALID-EXTRELOFF-OVERLAP: macho-invalid-extreloff-overlap': truncated or malformed object (external relocation table at offset 424 with a size of 8, overlaps reference table at offset 424 with a size of 4) + +RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-locreloff-overlap 2>&1 | FileCheck -check-prefix INVALID-LOCRELOFF-OVERLAP %s +INVALID-LOCRELOFF-OVERLAP: macho-invalid-locreloff-overlap': truncated or malformed object (local relocation table at offset 432 with a size of 8, overlaps external relocation table at offset 428 with a size of 8) + +RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-hints-overlap 2>&1 | FileCheck -check-prefix INVALID-HINTS-OVERLAP %s +INVALID-HINTS-OVERLAP: macho-invalid-hints-overlap': truncated or malformed object (two level hints at offset 104 with a size of 4, overlaps Mach-O headers at offset 0 with a size of 108) + +RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-codesig-overlap 2>&1 | FileCheck -check-prefix INVALID-CODESIG-OVERLAP %s +INVALID-CODESIG-OVERLAP: macho-invalid-codesig-overlap': truncated or malformed object (code signature data at offset 40 with a size of 32, overlaps Mach-O headers at offset 0 with a size of 48) + +RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-rebase-overlap 2>&1 | FileCheck -check-prefix INVALID-REBASE-OVERLAP %s +INVALID-REBASE-OVERLAP: macho-invalid-rebase-overlap': truncated or malformed object (dyld rebase info at offset 72 with a size of 32, overlaps Mach-O headers at offset 0 with a size of 80) + +RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-bind-overlap 2>&1 | FileCheck -check-prefix INVALID-BIND-OVERLAP %s +INVALID-BIND-OVERLAP: macho-invalid-bind-overlap': truncated or malformed object (dyld bind info at offset 104 with a size of 32, overlaps dyld rebase info at offset 80 with a size of 32) + +RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-weak_bind-overlap 2>&1 | FileCheck -check-prefix INVALID-WEAK_BIND-OVERLAP %s +INVALID-WEAK_BIND-OVERLAP: macho-invalid-weak_bind-overlap': truncated or malformed object (dyld weak bind info at offset 136 with a size of 32, overlaps dyld bind info at offset 112 with a size of 32) + +RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-lazy_bind-overlap 2>&1 | FileCheck -check-prefix INVALID-LAZY_BIND-OVERLAP %s +INVALID-LAZY_BIND-OVERLAP: macho-invalid-lazy_bind-overlap': truncated or malformed object (dyld lazy bind info at offset 168 with a size of 32, overlaps dyld weak bind info at offset 144 with a size of 32) + +RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-export-overlap 2>&1 | FileCheck -check-prefix INVALID-EXPORT-OVERLAP %s +INVALID-EXPORT-OVERLAP: macho-invalid-export-overlap': truncated or malformed object (dyld export info at offset 200 with a size of 32, overlaps dyld lazy bind info at offset 176 with a size of 32) diff --git a/llvm/test/tools/llvm-objdump/X86/malformed-machos.test b/llvm/test/tools/llvm-objdump/X86/malformed-machos.test index 9ada3ef..499c23e 100644 --- a/llvm/test/tools/llvm-objdump/X86/malformed-machos.test +++ b/llvm/test/tools/llvm-objdump/X86/malformed-machos.test @@ -7,17 +7,17 @@ # m0001: mem-crup-0001.macho': truncated or malformed object (addr field plus size of section 2 in LC_SEGMENT_64 command 0 greater than than the segment's vmaddr plus vmsize) -# RUN: llvm-objdump -macho -objc-meta-data \ -# RUN: %p/Inputs/malformed-machos/mem-crup-0006.macho \ +# RUN: not llvm-objdump -macho -objc-meta-data \ +# RUN: %p/Inputs/malformed-machos/mem-crup-0006.macho 2>&1 \ # RUN: | FileCheck -check-prefix=m0006 %s -# m0006: ivarLayout 0x8 +# m0006: malformed-machos/mem-crup-0006.macho': truncated or malformed object (section contents at offset 4128 with a size of 176, overlaps section contents at offset 4128 with a size of 8) -# RUN: llvm-objdump -macho -objc-meta-data \ -# RUN: %p/Inputs/malformed-machos/mem-crup-0006.macho \ +# RUN: not llvm-objdump -macho -objc-meta-data \ +# RUN: %p/Inputs/malformed-machos/mem-crup-0010.macho 2>&1 \ # RUN: | FileCheck -check-prefix=m0010 %s -# m0010: 00000000000010e0 0x10e8 _OBJC_CLASS_ +# m0010: mem-crup-0010.macho': truncated or malformed object (section contents at offset 4320 with a size of 80, overlaps section contents at offset 4320 with a size of 8) # RUN: not llvm-objdump -macho -objc-meta-data \ # RUN: %p/Inputs/malformed-machos/mem-crup-0040.macho 2>&1 \ @@ -34,8 +34,8 @@ # RUN: llvm-objdump -macho -objc-meta-data \ # RUN: %p/Inputs/malformed-machos/mem-crup-0261.macho -# RUN: llvm-objdump -macho -disassemble \ -# RUN: %p/Inputs/malformed-machos/mem-crup-0337.macho \ +# RUN: not llvm-objdump -macho -disassemble \ +# RUN: %p/Inputs/malformed-machos/mem-crup-0337.macho 2>&1 \ # RUN: | FileCheck -check-prefix=m0337 %s -# m0337: subq $16, %rsp +# m0337: mem-crup-0337.macho': truncated or malformed object (section relocation entries at offset 0 with a size of 512, overlaps Mach-O headers at offset 0 with a size of 2048)