[llvm] a28facb - [llvm] [dwarf] Fix DWARFListTableHeader::getOffsetEntry off-by-one

Jan Kratochvil via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 14 13:43:41 PDT 2021


Author: Jan Kratochvil
Date: 2021-03-14T21:42:44+01:00
New Revision: a28facba1ccdc957f386b7753f4958307f1bfde8

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

LOG: [llvm] [dwarf] Fix DWARFListTableHeader::getOffsetEntry off-by-one

D98289 was erroneously reporting `invalid range list offset 0x20110`
instead of `invalid range list table index 0`.

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

Added: 
    

Modified: 
    llvm/include/llvm/DebugInfo/DWARF/DWARFListTable.h
    llvm/unittests/DebugInfo/DWARF/DWARFListTableTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFListTable.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFListTable.h
index 94b647d3fbf4..53f3c754c206 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFListTable.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFListTable.h
@@ -113,7 +113,7 @@ class DWARFListTableHeader {
   void dump(DataExtractor Data, raw_ostream &OS,
             DIDumpOptions DumpOpts = {}) const;
   Optional<uint64_t> getOffsetEntry(DataExtractor Data, uint32_t Index) const {
-    if (Index > HeaderData.OffsetEntryCount)
+    if (Index >= HeaderData.OffsetEntryCount)
       return None;
 
     return getOffsetEntry(Data, getHeaderOffset() + getHeaderSize(Format), Format, Index);

diff  --git a/llvm/unittests/DebugInfo/DWARF/DWARFListTableTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFListTableTest.cpp
index ff7d71b5b052..8bb4d0fe59ba 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFListTableTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFListTableTest.cpp
@@ -73,4 +73,30 @@ TEST(DWARFListTableHeader, TruncatedHeader) {
   EXPECT_EQ(Header.length(), 6u);
 }
 
+TEST(DWARFListTableHeader, OffsetEntryCount) {
+  static const char SecData[] = "\x10\x00\x00\x00" // Length
+                                "\x05\x00"         // Version
+                                "\x08"             // Address size
+                                "\x00"             // Segment selector size
+                                "\x01\x00\x00\x00" // Offset entry count
+                                "\x04\x00\x00\x00" // offset[0]
+                                "\x04"             // DW_RLE_offset_pair
+                                "\x01"             // ULEB128 starting offset
+                                "\x02"             // ULEB128 ending offset
+                                "\x00";            // DW_RLE_end_of_list
+  DWARFDataExtractor Extractor(StringRef(SecData, sizeof(SecData) - 1),
+                               /*isLittleEndian=*/true,
+                               /*AddrSize=*/4);
+  DWARFListTableHeader Header(/*SectionName=*/".debug_rnglists",
+                              /*ListTypeString=*/"range");
+  uint64_t Offset = 0;
+  EXPECT_FALSE(!!Header.extract(Extractor, &Offset));
+  Optional<uint64_t> Offset0 = Header.getOffsetEntry(Extractor, 0);
+  EXPECT_TRUE(!!Offset0);
+  EXPECT_EQ(Offset0, uint64_t(4));
+  Optional<uint64_t> Offset1 = Header.getOffsetEntry(Extractor, 1);
+  EXPECT_FALSE(!!Offset1);
+  EXPECT_EQ(Header.length(), sizeof(SecData) - 1);
+}
+
 } // end anonymous namespace


        


More information about the llvm-commits mailing list