[lld] r282709 - [ELF] - Fixed crash on invalid input.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 29 04:10:40 PDT 2016
Author: grimar
Date: Thu Sep 29 06:10:40 2016
New Revision: 282709
URL: http://llvm.org/viewvc/llvm-project?rev=282709&view=rev
Log:
[ELF] - Fixed crash on invalid input.
I took the input from https://llvm.org/bugs/show_bug.cgi?id=30540, it was
"id_000000,sig_11,src_000000,op_flip1,pos_98"
File contains invalid symbol name offset (too large) and lld just crashes,
patch fixes the issue.
Differential revision: https://reviews.llvm.org/D24970
Added:
lld/trunk/test/ELF/invalid/Inputs/symbol-name-offset.elf (with props)
lld/trunk/test/ELF/invalid/symbol-name.s
Modified:
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=282709&r1=282708&r2=282709&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Sep 29 06:10:40 2016
@@ -380,7 +380,7 @@ template <class ELFT> void Writer<ELFT>:
if (!Out<ELFT>::SymTab)
return;
for (elf::ObjectFile<ELFT> *F : Symtab<ELFT>::X->getObjectFiles()) {
- const char *StrTab = F->getStringTable().data();
+ StringRef StrTab = F->getStringTable();
for (SymbolBody *B : F->getLocalSymbols()) {
auto *DR = dyn_cast<DefinedRegular<ELFT>>(B);
// No reason to keep local undefined symbol in symtab.
@@ -388,7 +388,9 @@ template <class ELFT> void Writer<ELFT>:
continue;
if (!includeInSymtab<ELFT>(*B))
continue;
- StringRef SymName(StrTab + B->getNameOffset());
+ if (B->getNameOffset() >= StrTab.size())
+ fatal(getFilename(F) + ": invalid symbol name offset");
+ StringRef SymName(StrTab.data() + B->getNameOffset());
InputSectionBase<ELFT> *Sec = DR->Section;
if (!shouldKeepInSymtab<ELFT>(Sec, SymName, *B))
continue;
Added: lld/trunk/test/ELF/invalid/Inputs/symbol-name-offset.elf
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/Inputs/symbol-name-offset.elf?rev=282709&view=auto
==============================================================================
Binary file - no diff available.
Propchange: lld/trunk/test/ELF/invalid/Inputs/symbol-name-offset.elf
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: lld/trunk/test/ELF/invalid/symbol-name.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/symbol-name.s?rev=282709&view=auto
==============================================================================
--- lld/trunk/test/ELF/invalid/symbol-name.s (added)
+++ lld/trunk/test/ELF/invalid/symbol-name.s Thu Sep 29 06:10:40 2016
@@ -0,0 +1,7 @@
+# REQUIRES: x86
+
+## symbol-name-offset.elf contains symbol with invalid (too large)
+## st_name value.
+# RUN: not ld.lld %S/Inputs/symbol-name-offset.elf \
+# RUN: -o %t 2>&1 | FileCheck %s
+# CHECK: invalid symbol name offset
More information about the llvm-commits
mailing list