Fix a bug in llvm-objdump’s printing of Objective-C meta data
authorKevin Enderby <enderby@apple.com>
Thu, 8 Oct 2015 16:56:35 +0000 (16:56 +0000)
committerKevin Enderby <enderby@apple.com>
Thu, 8 Oct 2015 16:56:35 +0000 (16:56 +0000)
from malformed Mach-O files that caused a crash because of loops
in the class meta data.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249700 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/llvm-objdump/Inputs/malformed-machos/mem-crup-0010.macho [new file with mode: 0644]
test/tools/llvm-objdump/malformed-machos.test
tools/llvm-objdump/MachODump.cpp

diff --git a/test/tools/llvm-objdump/Inputs/malformed-machos/mem-crup-0010.macho b/test/tools/llvm-objdump/Inputs/malformed-machos/mem-crup-0010.macho
new file mode 100644 (file)
index 0000000..4c7e78d
Binary files /dev/null and b/test/tools/llvm-objdump/Inputs/malformed-machos/mem-crup-0010.macho differ
index 4e1765f7f42fca37b3d17e5a824693ea3a09250f..e836239a250694c871f1b689ac8a8b4a40284ae0 100644 (file)
@@ -12,3 +12,9 @@
 # RUN:   | FileCheck -check-prefix=m0006 %s 
 
 # m0006: ivarLayout 0x8
+
+# RUN: llvm-objdump -macho -objc-meta-data \
+# RUN:   %p/Inputs/malformed-machos/mem-crup-0006.macho \
+# RUN:   | FileCheck -check-prefix=m0010 %s 
+
+# m0010: 00000000000010e0 0x10e8 _OBJC_CLASS_
index 0e9bf3695d80997f253f8ea2ccae782646ec4a89..b6b910f55dc749422a3497fde77867154ebb2639 100644 (file)
@@ -1667,6 +1667,7 @@ struct DisassembleInfo {
   uint64_t adrp_addr;
   uint32_t adrp_inst;
   BindTable *bindtable;
+  uint32_t depth;
 };
 
 // SymbolizerGetOpInfo() is the operand information call back function.
@@ -4463,9 +4464,13 @@ static void print_class64_t(uint64_t p, struct DisassembleInfo *info) {
   bool is_meta_class;
   print_class_ro64_t((c.data + n_value) & ~0x7, info, is_meta_class);
 
-  if (!is_meta_class) {
-    outs() << "Meta Class\n";
-    print_class64_t(c.isa + isa_n_value, info);
+  if (!is_meta_class &&
+      c.isa + isa_n_value != p &&
+      c.isa + isa_n_value != 0 &&
+      info->depth < 100) {
+      info->depth++;
+      outs() << "Meta Class\n";
+      print_class64_t(c.isa + isa_n_value, info);
   }
 }
 
@@ -5113,6 +5118,7 @@ static void printObjc2_64bit_MetaData(MachOObjectFile *O, bool verbose) {
   info.adrp_addr = 0;
   info.adrp_inst = 0;
 
+  info.depth = 0;
   const SectionRef CL = get_section(O, "__OBJC2", "__class_list");
   if (CL != SectionRef()) {
     info.S = CL;