]> granicus.if.org Git - llvm/commitdiff
[obj2yaml] Don't crash for input files without symbol table
authorAlexander Richardson <arichardson.kde@gmail.com>
Fri, 22 Sep 2017 09:30:40 +0000 (09:30 +0000)
committerAlexander Richardson <arichardson.kde@gmail.com>
Fri, 22 Sep 2017 09:30:40 +0000 (09:30 +0000)
Summary: Previously we would dereference Symtab without checking for null.

Reviewers: davide, atanasyan, rafael

Reviewed By: davide, atanasyan

Differential Revision: https://reviews.llvm.org/D38080

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

test/tools/obj2yaml/Inputs/crt1.o [new file with mode: 0755]
test/tools/obj2yaml/missing_symtab.test [new file with mode: 0644]
tools/obj2yaml/elf2yaml.cpp

diff --git a/test/tools/obj2yaml/Inputs/crt1.o b/test/tools/obj2yaml/Inputs/crt1.o
new file mode 100755 (executable)
index 0000000..2b000ab
Binary files /dev/null and b/test/tools/obj2yaml/Inputs/crt1.o differ
diff --git a/test/tools/obj2yaml/missing_symtab.test b/test/tools/obj2yaml/missing_symtab.test
new file mode 100644 (file)
index 0000000..b992931
--- /dev/null
@@ -0,0 +1,5 @@
+# RUN: obj2yaml %S/Inputs/crt1.o | FileCheck %s
+# test that we don't crash when passed object files without a symbol table
+# CHECK-LABEL: FileHeader:
+# CHECK-LABEL: Sections:
+# CHECK-LABEL: Symbols:
index 8997a5c4211b368afb3afc8d458c64e975c5e842..8c94843788f607b09dd8717952e340348c8b10bc 100644 (file)
@@ -188,6 +188,8 @@ template <class ELFT> ErrorOr<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
   }
 
   // Dump symbols
+  if (!Symtab)
+    return Y.release(); // if the symbol table is missing return early
   auto StrTableOrErr = Obj.getStringTableForSymtab(*Symtab);
   if (!StrTableOrErr)
     return errorToErrorCode(StrTableOrErr.takeError());