[llvm] b1c7bfe - [DebugInfo] Reject line tables of version > 5

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 10 06:45:09 PST 2020


Author: James Henderson
Date: 2020-02-10T14:43:10Z
New Revision: b1c7bfe6da2b5d171d025bf261f62773470cfc05

URL: https://github.com/llvm/llvm-project/commit/b1c7bfe6da2b5d171d025bf261f62773470cfc05
DIFF: https://github.com/llvm/llvm-project/commit/b1c7bfe6da2b5d171d025bf261f62773470cfc05.diff

LOG: [DebugInfo] Reject line tables of version > 5

If a debug line section with version of greater than 5 is encountered,
prior to this change the parser would accept it and treat it as version
5. This might work to some extent, but then it might not at all, as it
really depends on the format of the unspecified future version, which
will be different (otherwise there would be no point in changing the
version number). Any information we could provide has a good chance of
being invalid, so we should just refuse to parse such tables.

Reviewed by: dblaikie, MaskRay

Differential Revision: https://reviews.llvm.org/D74204

Added: 
    

Modified: 
    llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
    llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index b0f51f8aa912..bed6686680f9 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -327,7 +327,7 @@ Error DWARFDebugLine::Prologue::parse(
         PrologueOffset, TotalLength);
   }
   FormParams.Version = DebugLineData.getU16(OffsetPtr);
-  if (getVersion() < 2)
+  if (getVersion() < 2 || getVersion() > 5)
     // Treat this error as unrecoverable - we cannot be sure what any of
     // the data represents including the length field, so cannot skip it or make
     // any reasonable assumptions.

diff  --git a/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
index 0adac7c9ca9a..428f48ef08b9 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
@@ -354,6 +354,21 @@ TEST_F(DebugLineBasicFixture, ErrorForLowVersion) {
       "0x01");
 }
 
+TEST_F(DebugLineBasicFixture, ErrorForHighVersion) {
+  if (!setupGenerator())
+    return;
+
+  LineTable &LT = Gen->addLineTable();
+  LT.setCustomPrologue(
+      {{LineTable::Half, LineTable::Long}, {6, LineTable::Half}});
+
+  generate();
+
+  checkGetOrParseLineTableEmitsFatalError(
+      "parsing line table prologue at offset 0x00000000 found unsupported "
+      "version 0x06");
+}
+
 TEST_F(DebugLineBasicFixture, ErrorForInvalidV5IncludeDirTable) {
   if (!setupGenerator(5))
     return;


        


More information about the llvm-commits mailing list