[PATCH] D65391: [ELF.h] - Check the case when e_shstrndx=SHN_XINDEX, but the corresponding sh_link is broken.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 29 07:37:04 PDT 2019


grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added a reviewer: alexshap.
Herald added a subscriber: arphaman.

When e_shstrndx is equal to SHN_XINDEX,
the index of the section string table section should
be taken from zero section sh_link field.
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.

This is almost the same as D65388 <https://reviews.llvm.org/D65388>, but now the code
in ELF.h is tested.


https://reviews.llvm.org/D65391

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


Index: test/Object/invalid.test
===================================================================
--- test/Object/invalid.test
+++ test/Object/invalid.test
@@ -606,3 +606,23 @@
   Type:     ET_REL
   Machine:  EM_X86_64
   SHOffset: 0xffffffffffffffff
+
+## Check the case when e_shstrndx == SHN_XINDEX, but null section's sh_link contains
+## index of section header string table that is larger than number of the sections.
+
+# RUN: yaml2obj --docnum=29 %s -o %t29
+# RUN: not llvm-objcopy %t29 2>&1 | FileCheck %s -DFILE=%t29 --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
Index: include/llvm/Object/ELF.h
===================================================================
--- include/llvm/Object/ELF.h
+++ include/llvm/Object/ELF.h
@@ -466,7 +466,6 @@
 
   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");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65391.212143.patch
Type: text/x-patch
Size: 1345 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190729/5319969d/attachment-0001.bin>


More information about the llvm-commits mailing list