From: Alexander Richardson Date: Fri, 22 Sep 2017 09:30:40 +0000 (+0000) Subject: [obj2yaml] Don't crash for input files without symbol table X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=229871c6966c49c512f7343b282606d1327393cf;p=llvm [obj2yaml] Don't crash for input files without symbol table 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 --- diff --git a/test/tools/obj2yaml/Inputs/crt1.o b/test/tools/obj2yaml/Inputs/crt1.o new file mode 100755 index 00000000000..2b000ab9ae8 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 index 00000000000..b992931a0db --- /dev/null +++ b/test/tools/obj2yaml/missing_symtab.test @@ -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: diff --git a/tools/obj2yaml/elf2yaml.cpp b/tools/obj2yaml/elf2yaml.cpp index 8997a5c4211..8c94843788f 100644 --- a/tools/obj2yaml/elf2yaml.cpp +++ b/tools/obj2yaml/elf2yaml.cpp @@ -188,6 +188,8 @@ template ErrorOr ELFDumper::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());