[llvm] r285282 - [Object/ELF] - Do not crash if string table sh_size is equal to zero.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 27 04:41:58 PDT 2016


Author: grimar
Date: Thu Oct 27 06:41:57 2016
New Revision: 285282

URL: http://llvm.org/viewvc/llvm-project?rev=285282&view=rev
Log:
[Object/ELF] - Do not crash if string table sh_size is equal to zero.

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

Added:
    llvm/trunk/test/Object/Inputs/invalid-strtab-zero-size.elf   (with props)
Modified:
    llvm/trunk/include/llvm/Object/ELF.h
    llvm/trunk/test/Object/invalid.test

Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=285282&r1=285281&r2=285282&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Thu Oct 27 06:41:57 2016
@@ -428,6 +428,8 @@ ELFFile<ELFT>::getStringTable(const Elf_
   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());

Added: llvm/trunk/test/Object/Inputs/invalid-strtab-zero-size.elf
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/invalid-strtab-zero-size.elf?rev=285282&view=auto
==============================================================================
Binary file - no diff available.

Propchange: llvm/trunk/test/Object/Inputs/invalid-strtab-zero-size.elf
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: llvm/trunk/test/Object/invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/invalid.test?rev=285282&r1=285281&r2=285282&view=diff
==============================================================================
--- llvm/trunk/test/Object/invalid.test (original)
+++ llvm/trunk/test/Object/invalid.test Thu Oct 27 06:41:57 2016
@@ -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




More information about the llvm-commits mailing list