[Object, ELF] Fix segmentation fault in ELFFile::getSectionName().
authorAlexey Samsonov <vonosmas@gmail.com>
Thu, 4 Jun 2015 23:40:23 +0000 (23:40 +0000)
committerAlexey Samsonov <vonosmas@gmail.com>
Thu, 4 Jun 2015 23:40:23 +0000 (23:40 +0000)
Don't do a null dereference if .shstrtab section is missing.

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

include/llvm/Object/ELF.h
test/DebugInfo/Inputs/invalid.elf.no-shstrtab [new file with mode: 0644]
test/DebugInfo/dwarfdump-invalid.test

index e87737dcce7a65f32df728a3d0ab6222d519bea7..bca09bf7208f887d6e3a4493adf170b123227efe 100644 (file)
@@ -928,7 +928,7 @@ ErrorOr<StringRef> ELFFile<ELFT>::getSymbolName(const Elf_Shdr *Section,
 template <class ELFT>
 ErrorOr<StringRef>
 ELFFile<ELFT>::getSectionName(const Elf_Shdr *Section) const {
-  if (Section->sh_name >= dot_shstrtab_sec->sh_size)
+  if (!dot_shstrtab_sec || Section->sh_name >= dot_shstrtab_sec->sh_size)
     return object_error::parse_failed;
   return StringRef(getString(dot_shstrtab_sec, Section->sh_name));
 }
diff --git a/test/DebugInfo/Inputs/invalid.elf.no-shstrtab b/test/DebugInfo/Inputs/invalid.elf.no-shstrtab
new file mode 100644 (file)
index 0000000..e599695
Binary files /dev/null and b/test/DebugInfo/Inputs/invalid.elf.no-shstrtab differ
index da5b23e30ceb9fe9280d1bf5f4bdc541e689886e..4236d4f85e48378cc182499692b527811d1fecdd 100644 (file)
@@ -4,3 +4,6 @@ RUN: llvm-dwarfdump %p/Inputs/invalid.elf 2>&1 | FileCheck %s --check-prefix=INV
 RUN: llvm-dwarfdump %p/Inputs/invalid.elf.2 2>&1 | FileCheck %s --check-prefix=INVALID-ELF
 RUN: llvm-dwarfdump %p/Inputs/invalid.elf.3 2>&1 | FileCheck %s --check-prefix=INVALID-ELF
 INVALID-ELF: Invalid data was encountered while parsing the file
+
+RUN: llvm-dwarfdump %p/Inputs/invalid.elf.no-shstrtab 2>&1 | FileCheck %s --check-prefix=EMPTY
+EMPTY: .debug_info contents: