summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/InputFiles.cpp4
-rw-r--r--lld/test/elf2/Inputs/invalid-section-index.elfbin0 -> 544 bytes
-rw-r--r--lld/test/elf2/invalid-elf.test4
3 files changed, 8 insertions, 0 deletions
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index a58093f80a4..14566dccd32 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -93,6 +93,10 @@ SymbolBody *elf2::ObjectFile<ELFT>::createSymbolBody(StringRef StringTable,
if (SecIndex == SHN_XINDEX)
SecIndex = ELFObj->getExtendedSymbolTableIndex(Sym, Symtab, SymtabSHNDX);
+ if (SecIndex >= Chunks.size() ||
+ (SecIndex != 0 && !Chunks[SecIndex]))
+ error("Invalid section index");
+
switch (Sym->getBinding()) {
default:
error("unexpected binding");
diff --git a/lld/test/elf2/Inputs/invalid-section-index.elf b/lld/test/elf2/Inputs/invalid-section-index.elf
new file mode 100644
index 00000000000..ec5adcf3b0b
--- /dev/null
+++ b/lld/test/elf2/Inputs/invalid-section-index.elf
Binary files differ
diff --git a/lld/test/elf2/invalid-elf.test b/lld/test/elf2/invalid-elf.test
index 5b2bea3994f..0085b2797a9 100644
--- a/lld/test/elf2/invalid-elf.test
+++ b/lld/test/elf2/invalid-elf.test
@@ -13,3 +13,7 @@ INVALID-SYMTAB-SHINFO: Invalid sh_info in symbol table
RUN: not lld -flavor gnu2 %p/Inputs/invalid-binding.elf -o %t2 2>&1 | \
RUN: FileCheck --check-prefix=INVALID-BINDING %s
INVALID-BINDING: unexpected binding
+
+RUN: not lld -flavor gnu2 %p/Inputs/invalid-section-index.elf -o %t2 2>&1 | \
+RUN: FileCheck --check-prefix=INVALID-SECTION-INDEX %s
+INVALID-SECTION-INDEX: Invalid section index
OpenPOWER on IntegriCloud