1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

InstrProf: Actually detect bad headers

<rdar://problem/15950346>

llvm-svn: 204510
This commit is contained in:
Duncan P. N. Exon Smith 2014-03-21 20:42:28 +00:00
parent 215a35c5c8
commit 3920850b70
4 changed files with 14 additions and 7 deletions

View File

@ -27,6 +27,7 @@ struct instrprof_error {
success = 0, success = 0,
eof, eof,
bad_magic, bad_magic,
bad_header,
unsupported_version, unsupported_version,
too_large, too_large,
truncated, truncated,

View File

@ -29,6 +29,8 @@ class InstrProfErrorCategoryType : public error_category {
return "End of File"; return "End of File";
case instrprof_error::bad_magic: case instrprof_error::bad_magic:
return "Invalid file format (bad magic)"; return "Invalid file format (bad magic)";
case instrprof_error::bad_header:
return "Invalid header";
case instrprof_error::unsupported_version: case instrprof_error::unsupported_version:
return "Unsupported format version"; return "Unsupported format version";
case instrprof_error::too_large: case instrprof_error::too_large:

View File

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

View File

@ -0,0 +1,6 @@
RUN: printf "warforpl" > %t
RUN: not llvm-profdata show %t 2>&1 | FileCheck %s
RUN: printf "lprofraw" > %t
RUN: not llvm-profdata show %t 2>&1 | FileCheck %s
CHECK: error: {{.+}}: Invalid header