[llvm] f38f068 - [llvm-readelf] - Do not crash when dumping the dynamic symbol table when its sh_entzize == 0.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 22 05:42:09 PDT 2020
Author: Georgii Rymar
Date: 2020-06-22T15:41:34+03:00
New Revision: f38f068b14d8ae131278ae38f55f4e9b77c9d7f8
URL: https://github.com/llvm/llvm-project/commit/f38f068b14d8ae131278ae38f55f4e9b77c9d7f8
DIFF: https://github.com/llvm/llvm-project/commit/f38f068b14d8ae131278ae38f55f4e9b77c9d7f8.diff
LOG: [llvm-readelf] - Do not crash when dumping the dynamic symbol table when its sh_entzize == 0.
We have a division by zero crash currently when
the sh_entzize of the dynamic symbol table is 0.
Differential revision: https://reviews.llvm.org/D82180
Added:
Modified:
llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test b/llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test
index 0cb338616f94..817d52f41952 100644
--- a/llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test
+++ b/llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test
@@ -490,3 +490,26 @@ ProgramHeaders:
Sections:
- Section: .dynstr
- Section: .dynamic
+
+## Check we report a warning when the entry size of the dynamic symbol table is zero.
+# RUN: yaml2obj %s --docnum=14 -o %t15
+# RUN: llvm-readobj --dyn-symbols %t15 2>&1 | FileCheck %s -DFILE=%t15 --check-prefix=DYNSYM-ZERO-ENTSIZE-LLVM
+# RUN: llvm-readelf --dyn-symbols %t15 2>&1 | \
+# RUN: FileCheck %s -DFILE=%t15 --check-prefix=DYNSYM-ZERO-ENTSIZE-GNU --implicit-check-not="Symbol table"
+
+# DYNSYM-ZERO-ENTSIZE-LLVM: DynamicSymbols [
+# DYNSYM-ZERO-ENTSIZE-LLVM-NEXT: warning: '[[FILE]]': section with index 1 has invalid size (0x10) or entry size (0x0)
+# DYNSYM-ZERO-ENTSIZE-LLVM-NEXT: ]
+
+# DYNSYM-ZERO-ENTSIZE-GNU: warning: '[[FILE]]': section with index 1 has invalid size (0x10) or entry size (0x0)
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_386
+Sections:
+ - Name: .dynsym
+ Type: SHT_DYNSYM
+ EntSize: 0x0
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 866cecab66ab..e38ae9d56fb3 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -678,8 +678,7 @@ void ELFDumper<ELFT>::printSymbolsHelper(bool IsDynamic) const {
StrTable = DynamicStringTable;
Syms = dynamic_symbols();
SymtabName = DynSymtabName;
- if (DynSymRegion)
- Entries = DynSymRegion->Size / DynSymRegion->EntSize;
+ Entries = Syms.size();
} else {
if (!DotSymtabSec)
return;
More information about the llvm-commits
mailing list