[llvm] r284374 - Recommit r284371 "[Object/ELF] - Check that e_shnum is null when e_shoff is."

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 17 03:58:02 PDT 2016


Author: grimar
Date: Mon Oct 17 05:58:02 2016
New Revision: 284374

URL: http://llvm.org/viewvc/llvm-project?rev=284374&view=rev
Log:
Recommit r284371 "[Object/ELF] - Check that e_shnum is null when e_shoff is."
With fix: hex edited the precompiled inputs from another testcases to pass new checks.

Original commit message:

[Object/ELF] - Check that e_shnum is null when e_shoff is.

Spec says (http://www.sco.com/developers/gabi/1998-04-29/ch4.eheader.html) :
e_shnum
This member holds the number of entries in the section header table. Thus the product of e_shentsize and e_shnum gives the section header table's size in bytes. If a file has no section header table, e_shnum holds the value zero.

Revealed using "id_000037,sig_11,src_000015,op_havoc,rep_8" from PR30540

That was the reason of crash in lld on incorrect input file.
Binary reduced using afl-min.

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

Added:
    llvm/trunk/test/Object/Inputs/invalid-e_shnum.elf
      - copied unchanged from r284372, llvm/trunk/test/Object/Inputs/invalid-e_shnum.elf
Modified:
    llvm/trunk/include/llvm/Object/ELF.h
    llvm/trunk/test/Object/Inputs/corrupt-invalid-strtab.elf.x86-64
    llvm/trunk/test/Object/Inputs/rel-no-sec-table.elf-x86-64
    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=284374&r1=284373&r2=284374&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Mon Oct 17 05:58:02 2016
@@ -319,8 +319,12 @@ ELFFile<ELFT>::ELFFile(StringRef Object,
 
   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;
 

Modified: llvm/trunk/test/Object/Inputs/corrupt-invalid-strtab.elf.x86-64
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/corrupt-invalid-strtab.elf.x86-64?rev=284374&r1=284373&r2=284374&view=diff
==============================================================================
Binary files llvm/trunk/test/Object/Inputs/corrupt-invalid-strtab.elf.x86-64 (original) and llvm/trunk/test/Object/Inputs/corrupt-invalid-strtab.elf.x86-64 Mon Oct 17 05:58:02 2016 differ

Modified: llvm/trunk/test/Object/Inputs/rel-no-sec-table.elf-x86-64
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/rel-no-sec-table.elf-x86-64?rev=284374&r1=284373&r2=284374&view=diff
==============================================================================
Binary files llvm/trunk/test/Object/Inputs/rel-no-sec-table.elf-x86-64 (original) and llvm/trunk/test/Object/Inputs/rel-no-sec-table.elf-x86-64 Mon Oct 17 05:58:02 2016 differ

Modified: llvm/trunk/test/Object/invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/invalid.test?rev=284374&r1=284373&r2=284374&view=diff
==============================================================================
--- llvm/trunk/test/Object/invalid.test (original)
+++ llvm/trunk/test/Object/invalid.test Mon Oct 17 05:58:02 2016
@@ -55,6 +55,9 @@ INVALID-SYMTAB-SIZE: Invalid data was en
 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




More information about the llvm-commits mailing list