forked from OSchip/llvm-project
[COFF] Don't trust a symbol's section number
This fixes a test which exposed an ASan issue. We assumed that a symbol's section number had a corresponding section without performing validation. llvm-svn: 263558
This commit is contained in:
parent
708eeb0519
commit
272de1e4d1
|
@ -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;
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ symbols:
|
|||
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
|
||||
- Name: .rdata
|
||||
Value: 0
|
||||
SectionNumber: 4
|
||||
SectionNumber: 3
|
||||
SimpleType: IMAGE_SYM_TYPE_NULL
|
||||
ComplexType: IMAGE_SYM_DTYPE_NULL
|
||||
StorageClass: IMAGE_SYM_CLASS_STATIC
|
||||
|
|
Loading…
Reference in New Issue