[PATCH] D77554: [DWARFDebugLine] Check for (EOF) errors when parsing v5 content descriptors
Pavel Labath via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 6 08:06:21 PDT 2020
labath created this revision.
labath added reviewers: dblaikie, probinson, jhenderson.
Herald added subscribers: MaskRay, hiraditya.
Herald added a project: LLVM.
labath added a child revision: D77557: [DWARFDebugLine] Use truncating data extractors for prologue parsing.
Without that we could be silently reading zeroes, as that's the default
DataExtractor behavior. The entire parse would still most likely fail,
but it would do that with a seemingly unrelated/nonsensical error
message.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D77554
Files:
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
llvm/test/tools/llvm-dwarfdump/X86/debug_line_short_prologue.s
Index: llvm/test/tools/llvm-dwarfdump/X86/debug_line_short_prologue.s
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-dwarfdump/X86/debug_line_short_prologue.s
@@ -0,0 +1,37 @@
+# RUN: llvm-mc -triple x86_64-pc-linux %s -filetype=obj -o %t
+# RUN: llvm-dwarfdump -debug-line %t 2>&1 | FileCheck %s
+
+# CHECK: debug_line[0x00000000]
+# CHECK-NEXT: warning: parsing line table prologue at 0x00000000 found an invalid directory or file table description at 0x0000002b
+# CHECK-NEXT: warning: failed to parse entry content descriptors: malformed uleb128, extends past end
+# CHECK: include_directories[ 0] = "/tmp"
+
+.section .debug_line,"", at progbits
+.long .Lshort_prologue_end1-.Lshort_prologue_start1 # Length of Unit
+.Lshort_prologue_start1:
+.short 5 # DWARF version number
+.byte 8 # Address Size
+.byte 0 # Segment Selector Size
+.long .Lshort_prologue_header_end1 - .Lshort_prologue_params1 # Length of Prologue
+.Lshort_prologue_params1:
+.byte 1 # Minimum Instruction Length
+.byte 1 # Maximum Operations per Instruction
+.byte 1 # Default is_stmt
+.byte -5 # Line Base
+.byte 14 # Line Range
+.byte 13 # Opcode Base
+.byte 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 # Standard Opcode Lengths
+# Directory table format
+.byte 1 # One element per directory entry
+.byte 1 # DW_LNCT_path
+.byte 0x08 # DW_FORM_string
+# Directory table entries
+.byte 1 # 1 directory
+.asciz "/tmp"
+# File table format
+.byte 2 # 2 elements per file entry
+.byte 1 # DW_LNCT_path
+.byte 0x08 # DW_FORM_string
+.byte 5 # DW_LNCT_MD5
+.Lshort_prologue_header_end1:
+.Lshort_prologue_end1:
Index: llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
===================================================================
--- llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -219,14 +219,15 @@
static llvm::Expected<ContentDescriptors>
parseV5EntryFormat(const DWARFDataExtractor &DebugLineData, uint64_t *OffsetPtr,
DWARFDebugLine::ContentTypeTracker *ContentTypes) {
+ Error Err = Error::success();
ContentDescriptors Descriptors;
- int FormatCount = DebugLineData.getU8(OffsetPtr);
+ int FormatCount = DebugLineData.getU8(OffsetPtr, &Err);
bool HasPath = false;
- for (int I = 0; I != FormatCount; ++I) {
+ for (int I = 0; I != FormatCount && !Err; ++I) {
ContentDescriptor Descriptor;
Descriptor.Type =
- dwarf::LineNumberEntryFormat(DebugLineData.getULEB128(OffsetPtr));
- Descriptor.Form = dwarf::Form(DebugLineData.getULEB128(OffsetPtr));
+ dwarf::LineNumberEntryFormat(DebugLineData.getULEB128(OffsetPtr, &Err));
+ Descriptor.Form = dwarf::Form(DebugLineData.getULEB128(OffsetPtr, &Err));
if (Descriptor.Type == dwarf::DW_LNCT_path)
HasPath = true;
if (ContentTypes)
@@ -234,6 +235,11 @@
Descriptors.push_back(Descriptor);
}
+ if (Err)
+ return createStringError(errc::invalid_argument,
+ "failed to parse entry content descriptors: %s",
+ toString(std::move(Err)).c_str());
+
if (!HasPath)
return createStringError(errc::invalid_argument,
"failed to parse entry content descriptions"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77554.255343.patch
Type: text/x-patch
Size: 3533 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200406/2ad44f56/attachment-0001.bin>
More information about the llvm-commits
mailing list