From 83f903f3522cad54b020b9d419f331f4e58985de Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Thu, 4 Jun 2015 23:40:23 +0000 Subject: [PATCH] [Object, ELF] Fix segmentation fault in ELFFile::getSectionName(). 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 | 2 +- test/DebugInfo/Inputs/invalid.elf.no-shstrtab | Bin 0 -> 52 bytes test/DebugInfo/dwarfdump-invalid.test | 3 +++ 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 test/DebugInfo/Inputs/invalid.elf.no-shstrtab diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h index e87737dcce7..bca09bf7208 100644 --- a/include/llvm/Object/ELF.h +++ b/include/llvm/Object/ELF.h @@ -928,7 +928,7 @@ ErrorOr ELFFile::getSymbolName(const Elf_Shdr *Section, template ErrorOr ELFFile::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 index 0000000000000000000000000000000000000000..e5996951fb18badf12792e1f40202f8d080dfed7 GIT binary patch literal 52 scmb<-^>JflWMpQ5f>XcVTK_x$i;+Qtfe|RA0Ts3YD|q|QiXA8b02xOK$p8QV literal 0 HcmV?d00001 diff --git a/test/DebugInfo/dwarfdump-invalid.test b/test/DebugInfo/dwarfdump-invalid.test index da5b23e30ce..4236d4f85e4 100644 --- a/test/DebugInfo/dwarfdump-invalid.test +++ b/test/DebugInfo/dwarfdump-invalid.test @@ -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: -- 2.34.1