summaryrefslogtreecommitdiffstats
path: root/lld/COFF/InputFiles.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/COFF/InputFiles.cpp')
-rw-r--r--lld/COFF/InputFiles.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index 23af1e89c34..bc866b61ed4 100644
--- a/lld/COFF/InputFiles.cpp
+++ b/lld/COFF/InputFiles.cpp
@@ -219,11 +219,21 @@ Defined *ObjectFile::createDefined(COFFSymbolRef Sym, const void *AuxP,
}
return new (Alloc) DefinedAbsolute(Name, Sym);
}
- if (Sym.getSectionNumber() == llvm::COFF::IMAGE_SYM_DEBUG)
+ int32_t SectionNumber = Sym.getSectionNumber();
+ if (SectionNumber == llvm::COFF::IMAGE_SYM_DEBUG)
return nullptr;
+ // Reserved sections numbers don't have contents.
+ if (llvm::COFF::isReservedSectionNumber(SectionNumber))
+ error(Twine("broken object file: ") + getName());
+
+ // This symbol references a section which is not present in the section
+ // header.
+ if ((uint32_t)SectionNumber >= SparseChunks.size())
+ error(Twine("broken object file: ") + getName());
+
// Nothing else to do without a section chunk.
- auto *SC = cast_or_null<SectionChunk>(SparseChunks[Sym.getSectionNumber()]);
+ auto *SC = cast_or_null<SectionChunk>(SparseChunks[SectionNumber]);
if (!SC)
return nullptr;
OpenPOWER on IntegriCloud