[Lldb-commits] [lldb] 0bf17f8 - [lldb] Test that unterminated DW_FORM_strp names are rejected (#237354)

via lldb-commits lldb-commits at lists.llvm.org
Fri Oct 30 12:47:46 PDT 2026


Author: Jonas Devlieghere
Date: 2026-10-30T19:47:41Z
New Revision: 0bf17f86c743040c45f1f59f24d1585fd8636f61

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

LOG: [lldb] Test that unterminated DW_FORM_strp names are rejected (#237354)

c38a7054a1d8 bounded DataExtractor::PeekCStr and converted
DWARFFormValue::AsCString, but only tested the DataExtractor and Mach-O
paths. Add a DWARF test so AsCString can't regress to returning a
pointer into a .debug_str string with no terminator.

Added: 
    

Modified: 
    lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp b/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
index 0b8551c7cfd89f..656f259d6a4f34 100644
--- a/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
+++ b/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
@@ -200,6 +200,59 @@ TEST(DWARFDIETest, PeekName) {
   EXPECT_EQ(unit->PeekDIEName(fifth_die_offset), "NameType2");
 }
 
+TEST(DWARFDIETest, UnterminatedStrp) {
+  // .debug_str is "cu\0AAA" with no terminator after "AAA".
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+  Machine: EM_386
+Sections:
+  - Name:            .debug_str
+    Type:            SHT_PROGBITS
+    Content:         '637500414141'
+DWARF:
+  debug_abbrev:
+    - Table:
+        - Code:            0x00000001
+          Tag:             DW_TAG_compile_unit
+          Children:        DW_CHILDREN_yes
+          Attributes:
+            - Attribute:       DW_AT_name
+              Form:            DW_FORM_strp
+        - Code:            0x00000002
+          Tag:             DW_TAG_subprogram
+          Children:        DW_CHILDREN_no
+          Attributes:
+            - Attribute:       DW_AT_name
+              Form:            DW_FORM_strp
+  debug_info:
+    - Version:         4
+      AddrSize:        8
+      Entries:
+        - AbbrCode:        0x00000001
+          Values:
+            - Value:           0x0000000000000000
+        - AbbrCode:        0x00000002
+          Values:
+            - Value:           0x0000000000000003
+        - AbbrCode:        0x00000000
+)";
+
+  YAMLModuleTester t(yamldata);
+  DWARFUnit *unit = t.GetDwarfUnit();
+  ASSERT_TRUE(unit);
+
+  DWARFDIE cu_die = unit->DIE();
+  EXPECT_STREQ(cu_die.GetName(), "cu");
+
+  DWARFDIE subprogram_die = cu_die.GetFirstChild();
+  ASSERT_TRUE(subprogram_die);
+  EXPECT_EQ(subprogram_die.GetName(), nullptr);
+}
+
 TEST(DWARFDIETest, GetContext) {
   const char *yamldata = R"(
 --- !ELF


        


More information about the lldb-commits mailing list