]> granicus.if.org Git - llvm/commitdiff
[Object/ELF] - Do not crash if string table sh_size is equal to zero.
authorGeorge Rimar <grimar@accesssoftek.com>
Thu, 27 Oct 2016 11:41:57 +0000 (11:41 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Thu, 27 Oct 2016 11:41:57 +0000 (11:41 +0000)
Revealed using "id_000038,sig_11,src_000015,op_havoc,rep_16" from PR30540,
when sh_size was 0, crash happened.

Differential revision: https://reviews.llvm.org/D25091

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

include/llvm/Object/ELF.h
test/Object/Inputs/invalid-strtab-zero-size.elf [new file with mode: 0644]
test/Object/invalid.test

index 7aee6b1757451f18d5ece68ecd3653833a66a856..b6d4b804c27d4447c5fd8407767ea6ebd95147c3 100644 (file)
@@ -428,6 +428,8 @@ ELFFile<ELFT>::getStringTable(const Elf_Shdr *Section) const {
   if (std::error_code EC = V.getError())
     return EC;
   ArrayRef<char> Data = *V;
+  if (Data.empty())
+    return object_error::parse_failed;
   if (Data.back() != '\0')
     return object_error::string_table_non_null_end;
   return StringRef(Data.begin(), Data.size());
diff --git a/test/Object/Inputs/invalid-strtab-zero-size.elf b/test/Object/Inputs/invalid-strtab-zero-size.elf
new file mode 100644 (file)
index 0000000..cb0d0d0
Binary files /dev/null and b/test/Object/Inputs/invalid-strtab-zero-size.elf differ
index fda5d6d66d6bc2480cd1fa78202295ea903aaf60..352917987deb6533e9334b2c6edfd2b01aed7ec8 100644 (file)
@@ -1,6 +1,7 @@
 RUN: not llvm-dwarfdump %p/Inputs/invalid-bad-rel-type.elf 2>&1 | FileCheck %s
 RUN: not llvm-objdump -s %p/Inputs/invalid-strtab-type.elf 2>&1 | FileCheck %s
 RUN: not llvm-objdump -s %p/Inputs/invalid-strtab-size.elf 2>&1 | FileCheck %s
+RUN: not llvm-objdump -s %p/Inputs/invalid-strtab-zero-size.elf 2>&1 | FileCheck %s
 CHECK: Invalid data was encountered while parsing the file
 
 RUN: not llvm-objdump -s %p/Inputs/invalid-strtab-non-null.elf 2>&1 | FileCheck --check-prefix=NON-NULL %s