From: Kevin Enderby Date: Fri, 3 Nov 2017 21:32:44 +0000 (+0000) Subject: Fix a crash in llvm-objdump when printing a bad x86_64 relocation in a Mach-O X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3fc9188fa8cb939539e568a0ef602892aa3fc59a;p=platform%2Fupstream%2Fllvm.git Fix a crash in llvm-objdump when printing a bad x86_64 relocation in a Mach-O file with a bad section number. rdar://35207539 llvm-svn: 317373 --- diff --git a/llvm/test/tools/llvm-objdump/X86/Inputs/macho-invalid-reloc-section-index b/llvm/test/tools/llvm-objdump/X86/Inputs/macho-invalid-reloc-section-index new file mode 100644 index 0000000..a9d0b48 Binary files /dev/null and b/llvm/test/tools/llvm-objdump/X86/Inputs/macho-invalid-reloc-section-index differ diff --git a/llvm/test/tools/llvm-objdump/X86/malformed-machos.test b/llvm/test/tools/llvm-objdump/X86/malformed-machos.test index 292666a..e29df46 100644 --- a/llvm/test/tools/llvm-objdump/X86/malformed-machos.test +++ b/llvm/test/tools/llvm-objdump/X86/malformed-machos.test @@ -66,3 +66,6 @@ INVALID-SYMBOL-LIB_ORDINAL: macho-invalid-symbol-lib_ordinal': truncated or malf RUN: not llvm-objdump -macho -objc-meta-data %p/Inputs/macho-invalid-bind-entry 2>&1 | FileCheck -check-prefix INVALID-BIND-ENTRY %s INVALID-BIND-ENTRY: macho-invalid-bind-entry': truncated or malformed object (for BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB bad library ordinal: 83 (max 0) for opcode at: 0x0) + +RUN: llvm-objdump -macho -r %p/Inputs/macho-invalid-reloc-section-index | FileCheck -check-prefix INVALID-RELOC-SECTION-INDEX %s +INVALID-RELOC-SECTION-INDEX: 0000000000000021 X86_64_RELOC_UNSIGNED 8388613 (?,?) diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index d80f1cb..02eaa89 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -865,8 +865,19 @@ static void printRelocationTargetName(const MachOObjectFile *O, } else { section_iterator SI = O->section_begin(); // Adjust for the fact that sections are 1-indexed. - advance(SI, Val - 1); - SI->getName(S); + if (Val == 0) { + fmt << "0 (?,?)"; + return; + } + uint32_t i = Val - 1; + while (i != 0 && SI != O->section_end()) { + i--; + advance(SI, 1); + } + if (SI == O->section_end()) + fmt << Val << " (?,?)"; + else + SI->getName(S); } fmt << S;