[lld] r263558 - [COFF] Don't trust a symbol's section number
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 15 09:47:29 PDT 2016
Author: majnemer
Date: Tue Mar 15 11:47:28 2016
New Revision: 263558
URL: http://llvm.org/viewvc/llvm-project?rev=263558&view=rev
Log:
[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.
Modified:
lld/trunk/COFF/InputFiles.cpp
lld/trunk/test/COFF/loadcfg.test
Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=263558&r1=263557&r2=263558&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Tue Mar 15 11:47:28 2016
@@ -219,11 +219,21 @@ Defined *ObjectFile::createDefined(COFFS
}
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;
Modified: lld/trunk/test/COFF/loadcfg.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/loadcfg.test?rev=263558&r1=263557&r2=263558&view=diff
==============================================================================
--- lld/trunk/test/COFF/loadcfg.test (original)
+++ lld/trunk/test/COFF/loadcfg.test Tue Mar 15 11:47:28 2016
@@ -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
More information about the llvm-commits
mailing list