Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 83f903f

Browse files
committed
[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
1 parent 22a5d49 commit 83f903f

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

include/llvm/Object/ELF.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ ErrorOr<StringRef> ELFFile<ELFT>::getSymbolName(const Elf_Shdr *Section,
928928
template <class ELFT>
929929
ErrorOr<StringRef>
930930
ELFFile<ELFT>::getSectionName(const Elf_Shdr *Section) const {
931-
if (Section->sh_name >= dot_shstrtab_sec->sh_size)
931+
if (!dot_shstrtab_sec || Section->sh_name >= dot_shstrtab_sec->sh_size)
932932
return object_error::parse_failed;
933933
return StringRef(getString(dot_shstrtab_sec, Section->sh_name));
934934
}
52 Bytes
Binary file not shown.

test/DebugInfo/dwarfdump-invalid.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ RUN: llvm-dwarfdump %p/Inputs/invalid.elf 2>&1 | FileCheck %s --check-prefix=INV
44
RUN: llvm-dwarfdump %p/Inputs/invalid.elf.2 2>&1 | FileCheck %s --check-prefix=INVALID-ELF
55
RUN: llvm-dwarfdump %p/Inputs/invalid.elf.3 2>&1 | FileCheck %s --check-prefix=INVALID-ELF
66
INVALID-ELF: Invalid data was encountered while parsing the file
7+
8+
RUN: llvm-dwarfdump %p/Inputs/invalid.elf.no-shstrtab 2>&1 | FileCheck %s --check-prefix=EMPTY
9+
EMPTY: .debug_info contents:

0 commit comments

Comments
 (0)