Skip to content

Commit

Permalink
[COFF] Don't trust a symbol's section number
Browse files Browse the repository at this point in the history
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
  • Loading branch information
majnemer committed Mar 15, 2016
1 parent 708eeb0 commit 272de1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions lld/COFF/InputFiles.cpp
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lld/test/COFF/loadcfg.test
Expand Up @@ -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
Expand Down

0 comments on commit 272de1e

Please sign in to comment.