[llvm] r317373 - Fix a crash in llvm-objdump when printing a bad x86_64 relocation in a Mach-O

Kevin Enderby via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 3 14:32:44 PDT 2017


Author: enderby
Date: Fri Nov  3 14:32:44 2017
New Revision: 317373

URL: http://llvm.org/viewvc/llvm-project?rev=317373&view=rev
Log:
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

Added:
    llvm/trunk/test/tools/llvm-objdump/X86/Inputs/macho-invalid-reloc-section-index   (with props)
Modified:
    llvm/trunk/test/tools/llvm-objdump/X86/malformed-machos.test
    llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp

Added: llvm/trunk/test/tools/llvm-objdump/X86/Inputs/macho-invalid-reloc-section-index
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/Inputs/macho-invalid-reloc-section-index?rev=317373&view=auto
==============================================================================
Binary file - no diff available.

Propchange: llvm/trunk/test/tools/llvm-objdump/X86/Inputs/macho-invalid-reloc-section-index
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: llvm/trunk/test/tools/llvm-objdump/X86/malformed-machos.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/malformed-machos.test?rev=317373&r1=317372&r2=317373&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/X86/malformed-machos.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/X86/malformed-machos.test Fri Nov  3 14:32:44 2017
@@ -66,3 +66,6 @@ INVALID-SYMBOL-LIB_ORDINAL: macho-invali
 
 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 (?,?)

Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=317373&r1=317372&r2=317373&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Fri Nov  3 14:32:44 2017
@@ -865,8 +865,19 @@ static void printRelocationTargetName(co
   } 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;




More information about the llvm-commits mailing list