[PATCH] D41615: [DebugInfo] Don't crash when given invalid DWARFv5 line table prologue.

Jonas Devlieghere via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 5 02:04:17 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL321863: [DebugInfo] Don't crash when given invalid DWARFv5 line table prologue. (authored by JDevlieghere, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41615?vs=128299&id=128718#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41615

Files:
  llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h
  llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
  llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
  llvm/trunk/test/DebugInfo/Inputs/invalid.linetable
  llvm/trunk/test/DebugInfo/dwarfdump-invalid-line-table.test


Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
===================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
@@ -64,8 +64,9 @@
                                  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 @@
     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 @@
   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:
Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
===================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -268,7 +268,7 @@
 
   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: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h
===================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h
@@ -50,6 +50,8 @@
     }
     llvm_unreachable("Invalid Format value");
   }
+
+  explicit operator bool() const { return Version && AddrSize; }
 };
 
 class DWARFFormValue {
Index: llvm/trunk/test/DebugInfo/dwarfdump-invalid-line-table.test
===================================================================
--- llvm/trunk/test/DebugInfo/dwarfdump-invalid-line-table.test
+++ llvm/trunk/test/DebugInfo/dwarfdump-invalid-line-table.test
@@ -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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41615.128718.patch
Type: text/x-patch
Size: 3026 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180105/2893d91f/attachment.bin>


More information about the llvm-commits mailing list