summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/Object/ELF.h6
-rw-r--r--llvm/test/Object/Inputs/invalid-e_shnum.elfbin0 -> 64 bytes
-rw-r--r--llvm/test/Object/invalid.test3
3 files changed, 8 insertions, 1 deletions
diff --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h
index 31f42f5f50c..03b172fe304 100644
--- a/llvm/include/llvm/Object/ELF.h
+++ b/llvm/include/llvm/Object/ELF.h
@@ -319,8 +319,12 @@ ELFFile<ELFT>::ELFFile(StringRef Object, std::error_code &EC)
Header = reinterpret_cast<const Elf_Ehdr *>(base());
- if (Header->e_shoff == 0)
+ if (Header->e_shoff == 0) {
+ if (Header->e_shnum != 0)
+ report_fatal_error(
+ "e_shnum should be zero if a file has no section header table");
return;
+ }
const uint64_t SectionTableOffset = Header->e_shoff;
diff --git a/llvm/test/Object/Inputs/invalid-e_shnum.elf b/llvm/test/Object/Inputs/invalid-e_shnum.elf
new file mode 100644
index 00000000000..0b46fbd8cec
--- /dev/null
+++ b/llvm/test/Object/Inputs/invalid-e_shnum.elf
Binary files differ
diff --git a/llvm/test/Object/invalid.test b/llvm/test/Object/invalid.test
index d940789b6dc..c72de062059 100644
--- a/llvm/test/Object/invalid.test
+++ b/llvm/test/Object/invalid.test
@@ -55,6 +55,9 @@ INVALID-SYMTAB-SIZE: Invalid data was encountered while parsing the file
RUN: not llvm-readobj -t %p/Inputs/invalid-xindex-size.elf 2>&1 | FileCheck --check-prefix=INVALID-XINDEX-SIZE %s
INVALID-XINDEX-SIZE: Invalid data was encountered while parsing the file.
+RUN: not llvm-readobj -t %p/Inputs/invalid-e_shnum.elf 2>&1 | FileCheck --check-prefix=INVALID-SH-NUM %s
+INVALID-SH-NUM: e_shnum should be zero if a file has no section header table
+
RUN: not llvm-readobj -t %p/Inputs/invalid-ext-symtab-index.elf-x86-64 2>&1 | \
RUN: FileCheck --check-prefix=INVALID-EXT-SYMTAB-INDEX %s
INVALID-EXT-SYMTAB-INDEX: Invalid symbol table index
OpenPOWER on IntegriCloud