Object/COFF: Fix PE reading.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@144148 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael J. Spencer 2011-11-08 23:34:07 +00:00
parent 737e9a2db2
commit 7151ddd6ef

View File

@ -345,7 +345,7 @@ error_code COFFObjectFile::getSectionContents(DataRefImpl Sec,
// data, as there's nothing that says that is not allowed. // data, as there's nothing that says that is not allowed.
uintptr_t con_start = uintptr_t(base()) + sec->PointerToRawData; uintptr_t con_start = uintptr_t(base()) + sec->PointerToRawData;
uintptr_t con_end = con_start + sec->SizeOfRawData; uintptr_t con_end = con_start + sec->SizeOfRawData;
if (con_end >= uintptr_t(Data->getBufferEnd())) if (con_end > uintptr_t(Data->getBufferEnd()))
return object_error::parse_failed; return object_error::parse_failed;
Result = StringRef(reinterpret_cast<const char*>(con_start), Result = StringRef(reinterpret_cast<const char*>(con_start),
sec->SizeOfRawData); sec->SizeOfRawData);
@ -424,7 +424,12 @@ relocation_iterator COFFObjectFile::getSectionRelEnd(DataRefImpl Sec) const {
} }
COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, error_code &ec) COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, error_code &ec)
: ObjectFile(Binary::isCOFF, Object, ec) { : ObjectFile(Binary::isCOFF, Object, ec)
, Header(0)
, SectionTable(0)
, SymbolTable(0)
, StringTable(0)
, StringTableSize(0) {
// Check that we at least have enough room for a header. // Check that we at least have enough room for a header.
if (!checkSize(Data, ec, sizeof(coff_file_header))) return; if (!checkSize(Data, ec, sizeof(coff_file_header))) return;
@ -437,7 +442,7 @@ COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, error_code &ec)
// PE/COFF, seek through MS-DOS compatibility stub and 4-byte // PE/COFF, seek through MS-DOS compatibility stub and 4-byte
// PE signature to find 'normal' COFF header. // PE signature to find 'normal' COFF header.
if (!checkSize(Data, ec, 0x3c + 8)) return; if (!checkSize(Data, ec, 0x3c + 8)) return;
HeaderStart += *reinterpret_cast<const ulittle32_t *>(base() + 0x3c); HeaderStart = *reinterpret_cast<const ulittle16_t *>(base() + 0x3c);
// Check the PE header. ("PE\0\0") // Check the PE header. ("PE\0\0")
if (std::memcmp(base() + HeaderStart, "PE\0\0", 4) != 0) { if (std::memcmp(base() + HeaderStart, "PE\0\0", 4) != 0) {
ec = object_error::parse_failed; ec = object_error::parse_failed;
@ -459,6 +464,7 @@ COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, error_code &ec)
Header->NumberOfSections * sizeof(coff_section))) Header->NumberOfSections * sizeof(coff_section)))
return; return;
if (Header->PointerToSymbolTable != 0) {
SymbolTable = SymbolTable =
reinterpret_cast<const coff_symbol *>(base() reinterpret_cast<const coff_symbol *>(base()
+ Header->PointerToSymbolTable); + Header->PointerToSymbolTable);
@ -482,6 +488,7 @@ COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, error_code &ec)
ec = object_error::parse_failed; ec = object_error::parse_failed;
return; return;
} }
}
ec = object_error::success; ec = object_error::success;
} }