Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 81a623d

Browse files
committed
[DebugInfo] Don't crash when given invalid DWARFv5 line table prologue.
This patch replaces an assertion with an explicit check for the validity of the FORM parameters. The assertion was triggered when the DWARFv5 line table contained a zero address size. This fixes OSS-Fuzz Issue 4644 https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4644 Differential revision: https://reviews.llvm.org/D41615 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321863 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 8681051 commit 81a623d

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

include/llvm/DebugInfo/DWARF/DWARFFormValue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ struct DWARFFormParams {
5050
}
5151
llvm_unreachable("Invalid Format value");
5252
}
53+
54+
explicit operator bool() const { return Version && AddrSize; }
5355
};
5456

5557
class DWARFFormValue {

lib/DebugInfo/DWARF/DWARFDebugLine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ bool DWARFDebugLine::Prologue::parse(const DWARFDataExtractor &DebugLineData,
268268

269269
if (getVersion() >= 5) {
270270
if (!parseV5DirFileTables(DebugLineData, OffsetPtr, EndPrologueOffset,
271-
getFormParams(), U, HasMD5, IncludeDirectories,
271+
FormParams, U, HasMD5, IncludeDirectories,
272272
FileNames)) {
273273
fprintf(stderr,
274274
"warning: parsing line table prologue at 0x%8.8" PRIx64

lib/DebugInfo/DWARF/DWARFFormValue.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ DWARFFormValue::getFixedByteSize(dwarf::Form Form,
6464
const DWARFFormParams Params) {
6565
switch (Form) {
6666
case DW_FORM_addr:
67-
assert(Params.Version && Params.AddrSize && "Invalid Params for form");
68-
return Params.AddrSize;
67+
if (Params)
68+
return Params.AddrSize;
69+
return None;
6970

7071
case DW_FORM_block: // ULEB128 length L followed by L bytes.
7172
case DW_FORM_block1: // 1 byte length L followed by L bytes.
@@ -86,8 +87,9 @@ DWARFFormValue::getFixedByteSize(dwarf::Form Form,
8687
return None;
8788

8889
case DW_FORM_ref_addr:
89-
assert(Params.Version && Params.AddrSize && "Invalid Params for form");
90-
return Params.getRefAddrByteSize();
90+
if (Params)
91+
return Params.getRefAddrByteSize();
92+
return None;
9193

9294
case DW_FORM_flag:
9395
case DW_FORM_data1:
@@ -118,8 +120,9 @@ DWARFFormValue::getFixedByteSize(dwarf::Form Form,
118120
case DW_FORM_line_strp:
119121
case DW_FORM_sec_offset:
120122
case DW_FORM_strp_sup:
121-
assert(Params.Version && Params.AddrSize && "Invalid Params for form");
122-
return Params.getDwarfOffsetByteSize();
123+
if (Params)
124+
return Params.getDwarfOffsetByteSize();
125+
return None;
123126

124127
case DW_FORM_data8:
125128
case DW_FORM_ref8:
680 Bytes
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Verify that dwarfdump doesn't crash on invalid line table prologue.
2+
OSS-Fuzz Issue 4644 (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4644)
3+
4+
RUN: llvm-dwarfdump --verbose %p/Inputs/invalid.linetable 2>&1 | FileCheck %s --check-prefix=INVALID-LINE-TABLE
5+
INVALID-LINE-TABLE: invalid directory or file table description

0 commit comments

Comments
 (0)