diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-03-21 20:42:28 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-03-21 20:42:28 +0000 |
commit | 531bb481e22f429157811f215c044ee0634f2c1f (patch) | |
tree | c3a796d0bf0314869ed8add29ee5f4aeecc3e0d9 /llvm/lib/ProfileData/InstrProfReader.cpp | |
parent | 83ba74fa3f16ff396b6d609c5dabf3eda3f221d2 (diff) | |
download | bcm5719-llvm-531bb481e22f429157811f215c044ee0634f2c1f.tar.gz bcm5719-llvm-531bb481e22f429157811f215c044ee0634f2c1f.zip |
InstrProf: Actually detect bad headers
<rdar://problem/15950346>
llvm-svn: 204510
Diffstat (limited to 'llvm/lib/ProfileData/InstrProfReader.cpp')
-rw-r--r-- | llvm/lib/ProfileData/InstrProfReader.cpp | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp index c563355599f..d2e5fbd9b9a 100644 --- a/llvm/lib/ProfileData/InstrProfReader.cpp +++ b/llvm/lib/ProfileData/InstrProfReader.cpp @@ -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; |