[PATCH] D25516: [Object/ELF] - Check index argument in getSymbol().

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 12 08:12:12 PDT 2016


grimar created this revision.
grimar added reviewers: rafael, davide.
grimar added subscribers: llvm-commits, grimar, evgeny777.

Without this check LLD crashes when SHT_GROUP section has invalid symbol index
because of next code:

template <class ELFT>
StringRef elf::ObjectFile<ELFT>::getShtGroupSignature(const Elf_Shdr &Sec) {
..

  const Elf_Sym *Sym = Obj.getSymbol(Symtab, Sec.sh_info);

..
}

If sh_info is too large, &Symbols[Index] just asserts.

No testcases provided because llvm-objdump/llvm-readelf does not use getSymbol() function.
Though if this be landed I will be happy to add testcase for lld showing the issue.


https://reviews.llvm.org/D25516

Files:
  ELF.h


Index: ELF.h
===================================================================
--- ELF.h
+++ ELF.h
@@ -168,7 +168,10 @@
   ErrorOr<const Elf_Shdr *> getSection(uint32_t Index) const;
 
   const Elf_Sym *getSymbol(const Elf_Shdr *Sec, uint32_t Index) const {
-    return &symbols(Sec)[Index];
+    Elf_Sym_Range Symbols = symbols(Sec);
+    if (Index > Symbols.size())
+      report_fatal_error("Invalid symbol index");
+    return &Symbols[Index];
   }
 
   ErrorOr<StringRef> getSectionName(const Elf_Shdr *Section) const;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25516.74383.patch
Type: text/x-patch
Size: 537 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161012/2100bf6a/attachment.bin>


More information about the llvm-commits mailing list