summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
diff options
context:
space:
mode:
authorJames Henderson <jh7370@my.bristol.ac.uk>2020-01-07 10:21:20 +0000
committerJames Henderson <jh7370@my.bristol.ac.uk>2020-01-07 10:22:35 +0000
commit216796f234c757b832898adec28d5d523c80dce2 (patch)
tree2a073b3eb9450ea9a89be536f8f201988f0e7ad3 /llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
parent051c4d5b7bcfb0c1feb69f4701086ac725322527 (diff)
downloadbcm5719-llvm-216796f234c757b832898adec28d5d523c80dce2.tar.gz
bcm5719-llvm-216796f234c757b832898adec28d5d523c80dce2.zip
[DebugInfo] Fix infinite loop caused by reading past debug_line end
If the claimed unit length of a debug line program is such that the line table would finish past the end of the .debug_line section, an infinite loop occurs because the data extractor will continue to "read" zeroes without changing the offset. This previously didn't hit an error because the line table program handles a series of zeroes as a bad extended opcode. This patch fixes the inifinite loop and adds a warning if the program doesn't fit in the available data. Reviewed by: JDevlieghere Differential Revision: https://reviews.llvm.org/D72279
Diffstat (limited to 'llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp')
-rw-r--r--llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index 93b60f1e504..8e7ce58957d 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -528,8 +528,23 @@ Error DWARFDebugLine::LineTable::parse(
if (PrologueErr)
return PrologueErr;
- const uint64_t EndOffset =
- DebugLineOffset + Prologue.TotalLength + Prologue.sizeofTotalLength();
+ uint64_t ProgramLength = Prologue.TotalLength + Prologue.sizeofTotalLength();
+ if (!DebugLineData.isValidOffsetForDataOfSize(DebugLineOffset,
+ ProgramLength)) {
+ assert(DebugLineData.size() > DebugLineOffset &&
+ "prologue parsing should handle invalid offset");
+ uint64_t BytesRemaining = DebugLineData.size() - DebugLineOffset;
+ RecoverableErrorCallback(
+ createStringError(errc::invalid_argument,
+ "line table program with offset 0x%8.8" PRIx64
+ " has length 0x%8.8" PRIx64 " but only 0x%8.8" PRIx64
+ " bytes are available",
+ DebugLineOffset, ProgramLength, BytesRemaining));
+ // Continue by capping the length at the number of remaining bytes.
+ ProgramLength = BytesRemaining;
+ }
+
+ const uint64_t EndOffset = DebugLineOffset + ProgramLength;
// See if we should tell the data extractor the address size.
if (DebugLineData.getAddressSize() == 0)
OpenPOWER on IntegriCloud