]> granicus.if.org Git - llvm/commitdiff
[ELF.h] - Check the case when e_shstrndx=SHN_XINDEX, but the corresponding sh_link...
authorGeorge Rimar <grimar@accesssoftek.com>
Wed, 7 Aug 2019 09:29:42 +0000 (09:29 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Wed, 7 Aug 2019 09:29:42 +0000 (09:29 +0000)
When e_shstrndx is equal to SHN_XINDEX,
the index of the section string table section should
be taken from the sh_link field of the section
header at index 0.

If sh_link is broken, e.g. contains an index that is
larger than number of sections, then error is reported.

This error message was untested before.

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

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

include/llvm/Object/ELF.h
test/Object/invalid.test

index 6febbc7c8ded3431997b44992fd25deb698a93d9..51216bb6929339494ace08d2118d797551ba5128 100644 (file)
@@ -465,7 +465,6 @@ ELFFile<ELFT>::getSectionStringTable(Elf_Shdr_Range Sections) const {
 
   if (!Index) // no section string table.
     return "";
-  // TODO: Test a case when the sh_link of the section with index 0 is broken.
   if (Index >= Sections.size())
     return createError("section header string table index " + Twine(Index) +
                        " does not exist");
index 04a332d5fa4a6e81eadc0322da537e33a18f1fcb..9086b87dda9bcff530c78ae1e5bbdf93f84db9b6 100644 (file)
@@ -652,3 +652,23 @@ Sections:
 DynamicSymbols:
   - Name:    foo
     Binding: STB_GLOBAL
+
+## Check the case when e_shstrndx == SHN_XINDEX, but null section's sh_link contains
+## the index of a section header string table that is larger than the number of the sections.
+
+# RUN: yaml2obj --docnum=31 %s -o %t31
+# RUN: not llvm-objcopy %t31 2>&1 | FileCheck %s -DFILE=%t31 --check-prefix=INVALID-SHSTRTAB-INDEX
+
+# INVALID-SHSTRTAB-INDEX: error: section header string table index 255 does not exist
+
+--- !ELF
+FileHeader:
+  Class:    ELFCLASS64
+  Data:     ELFDATA2LSB
+  Type:     ET_REL
+  Machine:  EM_X86_64
+## SHN_XINDEX == 0xffff.
+  SHStrNdx: 0xffff
+Sections:
+  - Type: SHT_NULL
+    Link: 0xff