[llvm] r320399 - [dwarfdump] Fix off-by-one bug in accelerator table extractor.
Jonas Devlieghere via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 11 10:22:47 PST 2017
Author: jdevlieghere
Date: Mon Dec 11 10:22:47 2017
New Revision: 320399
URL: http://llvm.org/viewvc/llvm-project?rev=320399&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp
llvm/trunk/test/DebugInfo/Inputs/dwarfdump-objc.x86_64.o
llvm/trunk/test/DebugInfo/dwarfdump-accel.test
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h?rev=320399&r1=320398&r2=320399&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h Mon Dec 11 10:22:47 2017
@@ -90,7 +90,7 @@ public:
DataExtractor StringSection)
: AccelSection(AccelSection), StringSection(StringSection) {}
- bool extract();
+ llvm::Error extract();
uint32_t getNumBuckets();
uint32_t getNumHashes();
uint32_t getSizeHdr();
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp?rev=320399&r1=320398&r2=320399&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp Mon Dec 11 10:22:47 2017
@@ -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; }
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=320399&r1=320398&r2=320399&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Mon Dec 11 10:22:47 2017
@@ -672,7 +672,8 @@ getAccelTable(std::unique_ptr<DWARFAccel
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;
}
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp?rev=320399&r1=320398&r2=320399&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFVerifier.cpp Mon Dec 11 10:22:47 2017
@@ -686,8 +686,8 @@ unsigned DWARFVerifier::verifyAccelTable
}
// 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;
}
Modified: llvm/trunk/test/DebugInfo/Inputs/dwarfdump-objc.x86_64.o
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Inputs/dwarfdump-objc.x86_64.o?rev=320399&r1=320398&r2=320399&view=diff
==============================================================================
Binary files llvm/trunk/test/DebugInfo/Inputs/dwarfdump-objc.x86_64.o (original) and llvm/trunk/test/DebugInfo/Inputs/dwarfdump-objc.x86_64.o Mon Dec 11 10:22:47 2017 differ
Modified: llvm/trunk/test/DebugInfo/dwarfdump-accel.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/dwarfdump-accel.test?rev=320399&r1=320398&r2=320399&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/dwarfdump-accel.test (original)
+++ llvm/trunk/test/DebugInfo/dwarfdump-accel.test Mon Dec 11 10:22:47 2017
@@ -69,6 +69,6 @@ Verify the debug info in the apple_names
VERIFY: Verifying .apple_names...
VERIFY-NEXT: Verifying .apple_types...
VERIFY-NEXT: Verifying .apple_namespaces...
-VERIFY-NEXT: error: Section is smaller than size described in section header.
+VERIFY-NEXT: error: Section too small: cannot read buckets and hashes.
VERIFY-NEXT: Verifying .apple_objc...
VERIFY-NEXT: Errors detected.
More information about the llvm-commits
mailing list