InstrProf: Actually detect bad headers

<rdar://problem/15950346>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204510 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2014-03-21 20:42:28 +00:00
parent 56db3a97cd
commit ebaeaa934e
4 changed files with 14 additions and 7 deletions

View File

@ -43,8 +43,7 @@ error_code InstrProfReader::create(std::string Path,
if (Buffer->getBufferSize() < sizeof(uint64_t)) {
Result.reset(new TextInstrProfReader(Buffer));
Result->readHeader();
return instrprof_error::success;
return Result->readHeader();
}
uint64_t Magic = *(uint64_t *)Buffer->getBufferStart();
@ -53,8 +52,7 @@ error_code InstrProfReader::create(std::string Path,
Result.reset(new RawInstrProfReader(Buffer));
else
Result.reset(new TextInstrProfReader(Buffer));
Result->readHeader();
return instrprof_error::success;
return Result->readHeader();
}
void InstrProfIterator::Increment() {
@ -113,13 +111,13 @@ RawInstrProfReader::RawInstrProfReader(std::unique_ptr<MemoryBuffer> &DataBuffer
error_code RawInstrProfReader::readHeader() {
if (DataBuffer->getBufferSize() < sizeof(RawHeader))
return error(instrprof_error::malformed);
return error(instrprof_error::bad_header);
const RawHeader *Header = (RawHeader *)DataBuffer->getBufferStart();
if (Header->Magic == getRawMagic())
ShouldSwapBytes = false;
else {
if (sys::SwapByteOrder(Header->Magic) != getRawMagic())
return error(instrprof_error::malformed);
return error(instrprof_error::bad_magic);
ShouldSwapBytes = true;
}
@ -142,7 +140,7 @@ error_code RawInstrProfReader::readHeader(const RawHeader &Header) {
size_t FileSize = NamesOffset + sizeof(char) * NamesSize;
if (FileSize != DataBuffer->getBufferSize())
return error(instrprof_error::malformed);
return error(instrprof_error::bad_header);
Data = (ProfileData *)(DataBuffer->getBufferStart() + DataOffset);
DataEnd = Data + DataSize;