OSDN Git Service

[DebugInfo] Don't crash when given invalid DWARFv5 line table prologue.
authorJonas Devlieghere <jonas@devlieghere.com>
Fri, 5 Jan 2018 10:03:02 +0000 (10:03 +0000)
committerJonas Devlieghere <jonas@devlieghere.com>
Fri, 5 Jan 2018 10:03:02 +0000 (10:03 +0000)
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

include/llvm/DebugInfo/DWARF/DWARFFormValue.h
lib/DebugInfo/DWARF/DWARFDebugLine.cpp
lib/DebugInfo/DWARF/DWARFFormValue.cpp
test/DebugInfo/Inputs/invalid.linetable [new file with mode: 0644]
test/DebugInfo/dwarfdump-invalid-line-table.test [new file with mode: 0644]

index d320535..2c0a942 100644 (file)
@@ -50,6 +50,8 @@ struct DWARFFormParams {
     }
     llvm_unreachable("Invalid Format value");
   }
+
+  explicit operator bool() const { return Version && AddrSize; }
 };
 
 class DWARFFormValue {
index e5ef4ea..861122c 100644 (file)
@@ -268,7 +268,7 @@ bool DWARFDebugLine::Prologue::parse(const DWARFDataExtractor &DebugLineData,
 
   if (getVersion() >= 5) {
     if (!parseV5DirFileTables(DebugLineData, OffsetPtr, EndPrologueOffset,
-                              getFormParams(), U, HasMD5, IncludeDirectories,
+                              FormParams, U, HasMD5, IncludeDirectories,
                               FileNames)) {
       fprintf(stderr,
               "warning: parsing line table prologue at 0x%8.8" PRIx64
index 44886de..769ac37 100644 (file)
@@ -64,8 +64,9 @@ DWARFFormValue::getFixedByteSize(dwarf::Form Form,
                                  const DWARFFormParams Params) {
   switch (Form) {
   case DW_FORM_addr:
-    assert(Params.Version && Params.AddrSize && "Invalid Params for form");
-    return Params.AddrSize;
+    if (Params)
+      return Params.AddrSize;
+    return None;
 
   case DW_FORM_block:          // ULEB128 length L followed by L bytes.
   case DW_FORM_block1:         // 1 byte length L followed by L bytes.
@@ -86,8 +87,9 @@ DWARFFormValue::getFixedByteSize(dwarf::Form Form,
     return None;
 
   case DW_FORM_ref_addr:
-    assert(Params.Version && Params.AddrSize && "Invalid Params for form");
-    return Params.getRefAddrByteSize();
+    if (Params)
+      return Params.getRefAddrByteSize();
+    return None;
 
   case DW_FORM_flag:
   case DW_FORM_data1:
@@ -118,8 +120,9 @@ DWARFFormValue::getFixedByteSize(dwarf::Form Form,
   case DW_FORM_line_strp:
   case DW_FORM_sec_offset:
   case DW_FORM_strp_sup:
-    assert(Params.Version && Params.AddrSize && "Invalid Params for form");
-    return Params.getDwarfOffsetByteSize();
+    if (Params)
+      return Params.getDwarfOffsetByteSize();
+    return None;
 
   case DW_FORM_data8:
   case DW_FORM_ref8:
diff --git a/test/DebugInfo/Inputs/invalid.linetable b/test/DebugInfo/Inputs/invalid.linetable
new file mode 100644 (file)
index 0000000..5df4139
Binary files /dev/null and b/test/DebugInfo/Inputs/invalid.linetable differ
diff --git a/test/DebugInfo/dwarfdump-invalid-line-table.test b/test/DebugInfo/dwarfdump-invalid-line-table.test
new file mode 100644 (file)
index 0000000..afcaec0
--- /dev/null
@@ -0,0 +1,5 @@
+Verify that dwarfdump doesn't crash on invalid line table prologue.
+OSS-Fuzz Issue 4644 (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4644)
+
+RUN: llvm-dwarfdump --verbose %p/Inputs/invalid.linetable 2>&1 | FileCheck %s --check-prefix=INVALID-LINE-TABLE
+INVALID-LINE-TABLE: invalid directory or file table description