[PATCH] D25025: [ELF] - Do not crash on invalid symbol index.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 3 03:36:41 PDT 2016


grimar updated the summary for this revision.
grimar updated this revision to Diff 73257.
grimar added a comment.

- Removed excessive test.


https://reviews.llvm.org/D25025

Files:
  ELF/InputFiles.h
  test/ELF/invalid/Inputs/invalid-symbol-index.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,10 @@
+## invalid-symbol-index.elf has incorrect type of .symtab section.
+## There is no symbol bodies because of that and any symbol index becomes incorrect.
+## 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
+# 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
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.73257.patch
Type: text/x-patch
Size: 1285 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161003/10842a0f/attachment.bin>


More information about the llvm-commits mailing list