diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2017-12-11 18:22:47 +0000 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2017-12-11 18:22:47 +0000 |
commit | 11c697c506c3339419d3231d9c899b08aec5a052 (patch) | |
tree | aba8c50f4272c1c22344b387117c08cf1c73c0c6 /lib/DebugInfo | |
parent | c7bd85c064c1a9af3c77d010674e78d96435c719 (diff) |
[dwarfdump] Fix off-by-one bug in accelerator table extractor.
This fixes a bug where the verifier was complaining about empty
accelerator tables. When the table is empty, its size is not a valid
offset as it points after the end of the section.
This patch also makes the extractor return llvm:Error instead of bool
for better error reporting in the verifier.
Differential revision: https://reviews.llvm.org/D41063
rdar://35932007
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320399 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/DebugInfo')
-rw-r--r-- | lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp | 15 | ||||
-rw-r--r-- | lib/DebugInfo/DWARF/DWARFContext.cpp | 3 | ||||
-rw-r--r-- | lib/DebugInfo/DWARF/DWARFVerifier.cpp | 4 |
3 files changed, 14 insertions, 8 deletions
diff --git a/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp b/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp index f04ec7706cd..670191418cd 100644 --- a/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp +++ b/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp @@ -22,12 +22,13 @@ using namespace llvm; -bool DWARFAcceleratorTable::extract() { +llvm::Error DWARFAcceleratorTable::extract() { uint32_t Offset = 0; // Check that we can at least read the header. if (!AccelSection.isValidOffset(offsetof(Header, HeaderDataLength)+4)) - return false; + return make_error<StringError>("Section too small: cannot read header.", + inconvertibleErrorCode()); Hdr.Magic = AccelSection.getU32(&Offset); Hdr.Version = AccelSection.getU16(&Offset); @@ -38,9 +39,13 @@ bool DWARFAcceleratorTable::extract() { // Check that we can read all the hashes and offsets from the // section (see SourceLevelDebugging.rst for the structure of the index). + // We need to substract one because we're checking for an *offset* which is + // equal to the size for an empty table and hence pointer after the section. if (!AccelSection.isValidOffset(sizeof(Hdr) + Hdr.HeaderDataLength + - Hdr.NumBuckets*4 + Hdr.NumHashes*8)) - return false; + Hdr.NumBuckets * 4 + Hdr.NumHashes * 8 - 1)) + return make_error<StringError>( + "Section too small: cannot read buckets and hashes.", + inconvertibleErrorCode()); HdrData.DIEOffsetBase = AccelSection.getU32(&Offset); uint32_t NumAtoms = AccelSection.getU32(&Offset); @@ -52,7 +57,7 @@ bool DWARFAcceleratorTable::extract() { } IsValid = true; - return true; + return Error::success(); } uint32_t DWARFAcceleratorTable::getNumBuckets() { return Hdr.NumBuckets; } diff --git a/lib/DebugInfo/DWARF/DWARFContext.cpp b/lib/DebugInfo/DWARF/DWARFContext.cpp index 414959c7a5c..a5defa90eb3 100644 --- a/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -672,7 +672,8 @@ getAccelTable(std::unique_ptr<DWARFAcceleratorTable> &Cache, DWARFDataExtractor AccelSection(Obj, Section, IsLittleEndian, 0); DataExtractor StrData(StringSection, IsLittleEndian, 0); Cache.reset(new DWARFAcceleratorTable(AccelSection, StrData)); - Cache->extract(); + if (Error E = Cache->extract()) + llvm::consumeError(std::move(E)); return *Cache; } diff --git a/lib/DebugInfo/DWARF/DWARFVerifier.cpp b/lib/DebugInfo/DWARF/DWARFVerifier.cpp index 8e07bb3c462..3d473698b46 100644 --- a/lib/DebugInfo/DWARF/DWARFVerifier.cpp +++ b/lib/DebugInfo/DWARF/DWARFVerifier.cpp @@ -686,8 +686,8 @@ unsigned DWARFVerifier::verifyAccelTable(const DWARFSection *AccelSection, } // Verify that the section is not too short. - if (!AccelTable.extract()) { - error() << "Section is smaller than size described in section header.\n"; + if (Error E = AccelTable.extract()) { + error() << toString(std::move(E)) << '\n'; return 1; } |