[PATCH] [Updated, 23 lines] D25025: [ELF] - Do not crash on invalid symbol index.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 30 02:04:59 PDT 2016


grimar retitled this revision from "[ELF, WIP] - Do not crash on invalid symbol index." to "[ELF] - Do not crash on invalid symbol index.".
grimar updated the summary for this revision.
grimar updated this revision to Diff 73008.
grimar added a comment.

- Rebased.
- Run afl-min on testcases (had no any changes in size).


https://reviews.llvm.org/D25025

Files:
  ELF/InputFiles.h
  test/ELF/invalid/Inputs/invalid-symbol-index.elf
  test/ELF/invalid/Inputs/invalid-symbol-index2.elf
  test/ELF/invalid/invalid-symbol-index.s


Index: test/ELF/invalid/invalid-symbol-index.s
===================================================================
--- test/ELF/invalid/invalid-symbol-index.s
+++ test/ELF/invalid/invalid-symbol-index.s
@@ -0,0 +1,21 @@
+## invalid-symbol-index.elf has incorrect type of .symtab section:
+## Section Headers:
+##   [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
+##   [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
+## ...
+##   [ 4] .symtab           RELA            0000000000000000 000048 000030 18      1   2  8
+## There is no symbol bodies because of that but relocations resolution tries to access them.
+# RUN: not ld.lld %p/Inputs/invalid-symbol-index.elf -o %t2 2>&1 | \
+# RUN:   FileCheck --check-prefix=INVALID-SYMBOL-INDEX %s
+# INVALID-SYMBOL-INDEX: invalid symbol index
+
+## invalid-symbol-index2.elf just contains wrong symbol index in relocation:
+## Relocation section '.rela.text' at offset 0x1c0 contains 1 entries:
+##     Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
+## 0000000000000123  000000ff00000002 R_X86_64_PC32          bad symbol index: 000000ff
+## 
+## Symbol table '.symtab' contains 1 entries:
+##    Num:    Value          Size Type    Bind   Vis      Ndx Name
+##      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
+# RUN: not ld.lld %p/Inputs/invalid-symbol-index2.elf -o %t2 2>&1 | \
+# RUN:   FileCheck --check-prefix=INVALID-SYMBOL-INDEX %s
Index: ELF/InputFiles.h
===================================================================
--- ELF/InputFiles.h
+++ ELF/InputFiles.h
@@ -151,6 +151,8 @@
   InputSectionBase<ELFT> *getSection(const Elf_Sym &Sym) const;
 
   SymbolBody &getSymbolBody(uint32_t SymbolIndex) const {
+    if (SymbolIndex >= SymbolBodies.size())
+      fatal("invalid symbol index");
     return *SymbolBodies[SymbolIndex];
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25025.73008.patch
Type: text/x-patch
Size: 1962 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160930/9d11bdd8/attachment.bin>


More information about the llvm-commits mailing list