[lld] r283201 - [ELF] - Do not crash on invalid symbol index.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 4 02:02:43 PDT 2016


Author: grimar
Date: Tue Oct  4 04:02:42 2016
New Revision: 283201

URL: http://llvm.org/viewvc/llvm-project?rev=283201&view=rev
Log:
[ELF] - Do not crash on invalid symbol index.

Relative to PR30540.

If .symtab has invalid type in elf, no bodies are created and any relocation
that tries to access them will fail.
The same can happen if symbol index is just incorrect.

This was revealed by "id_000005,sig_11,src_000000,op_flip2,pos_420"

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

Added:
    lld/trunk/test/ELF/invalid/Inputs/invalid-symbol-index.elf   (with props)
    lld/trunk/test/ELF/invalid/invalid-symbol-index.s
Modified:
    lld/trunk/ELF/InputFiles.h

Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=283201&r1=283200&r2=283201&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Tue Oct  4 04:02:42 2016
@@ -151,6 +151,8 @@ public:
   InputSectionBase<ELFT> *getSection(const Elf_Sym &Sym) const;
 
   SymbolBody &getSymbolBody(uint32_t SymbolIndex) const {
+    if (SymbolIndex >= SymbolBodies.size())
+      fatal(getFilename(this) + ": invalid symbol index");
     return *SymbolBodies[SymbolIndex];
   }
 

Added: lld/trunk/test/ELF/invalid/Inputs/invalid-symbol-index.elf
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/Inputs/invalid-symbol-index.elf?rev=283201&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lld/trunk/test/ELF/invalid/Inputs/invalid-symbol-index.elf
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lld/trunk/test/ELF/invalid/invalid-symbol-index.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/invalid-symbol-index.s?rev=283201&view=auto
==============================================================================
--- lld/trunk/test/ELF/invalid/invalid-symbol-index.s (added)
+++ lld/trunk/test/ELF/invalid/invalid-symbol-index.s Tue Oct  4 04:02:42 2016
@@ -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




More information about the llvm-commits mailing list