diff options
author | George Rimar <grimar@accesssoftek.com> | 2016-10-17 10:06:44 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2016-10-17 10:06:44 +0000 |
commit | 7d97e735892b478bde261c6a2f197c6deec1e18c (patch) | |
tree | 87f987f306336d001b66d2263b41abbd390f0b1b | |
parent | bd31488083f3d3db2603464026853d528cfdc07e (diff) | |
download | bcm5719-llvm-7d97e735892b478bde261c6a2f197c6deec1e18c.tar.gz bcm5719-llvm-7d97e735892b478bde261c6a2f197c6deec1e18c.zip |
[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
llvm-svn: 284371
-rw-r--r-- | llvm/include/llvm/Object/ELF.h | 6 | ||||
-rw-r--r-- | llvm/test/Object/Inputs/invalid-e_shnum.elf | bin | 0 -> 64 bytes | |||
-rw-r--r-- | llvm/test/Object/invalid.test | 3 |
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 Binary files differnew file mode 100644 index 00000000000..0b46fbd8cec --- /dev/null +++ b/llvm/test/Object/Inputs/invalid-e_shnum.elf 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 |