[ELF] - Added testcase relative to D25090.
authorGeorge Rimar <grimar@accesssoftek.com>
Mon, 17 Oct 2016 11:15:12 +0000 (11:15 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Mon, 17 Oct 2016 11:15:12 +0000 (11:15 +0000)
It was requested on review for https://reviews.llvm.org/D25090 to add testcase in lld.

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.

In case revealed, broken input did not contain zero in this field.
 LLD then could crash when proccessed sections (returned array has incorrect size):

template <class ELFT> void SharedFile<ELFT>::parseSoName() {
...
  for (const Elf_Shdr &Sec : Obj.sections()) {
...

llvm-svn: 284375

lld/test/ELF/invalid/Inputs/invalid-e_shnum.elf [new file with mode: 0644]
lld/test/ELF/invalid/invalid-e_shnum.s [new file with mode: 0644]

diff --git a/lld/test/ELF/invalid/Inputs/invalid-e_shnum.elf b/lld/test/ELF/invalid/Inputs/invalid-e_shnum.elf
new file mode 100644 (file)
index 0000000..0b46fbd
Binary files /dev/null and b/lld/test/ELF/invalid/Inputs/invalid-e_shnum.elf differ
diff --git a/lld/test/ELF/invalid/invalid-e_shnum.s b/lld/test/ELF/invalid/invalid-e_shnum.s
new file mode 100644 (file)
index 0000000..fc197e7
--- /dev/null
@@ -0,0 +1,4 @@
+## Spec says that "If a file has no section header table, e_shnum holds the value zero.", though
+## in this test case it holds non-zero and lld may crash.
+# RUN: not ld.lld %p/Inputs/invalid-e_shnum.elf -o %t2 2>&1 | FileCheck %s
+# CHECK: e_shnum should be zero if a file has no section header table
\ No newline at end of file