Skip to content

Commit 095c3c9

Browse files
authored
[LLDB] Fix crash in TypeSystemClang::GetIndexofChildMemberWithName. (#117808)
LLDB can crash in TypeSystemClang::GetIndexOfChildMemberWithName, at a point where it pushes an index onto the child_indexes vector, tries to call itself recursively, then tries to pop the entry from child_indexes. The problem is that the recursive call can clear child_indexes, so that this code ends up trying to pop an already empty vector. This change saves the old vector before the push, then restores the saved vector rather than trying to pop.
1 parent 4b11ff7 commit 095c3c9

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6754,12 +6754,12 @@ size_t TypeSystemClang::GetIndexOfChildMemberWithName(
67546754
llvm::StringRef field_name = field->getName();
67556755
if (field_name.empty()) {
67566756
CompilerType field_type = GetType(field->getType());
6757+
std::vector<uint32_t> save_indices = child_indexes;
67576758
child_indexes.push_back(child_idx);
67586759
if (field_type.GetIndexOfChildMemberWithName(
67596760
name, omit_empty_base_classes, child_indexes))
67606761
return child_indexes.size();
6761-
child_indexes.pop_back();
6762-
6762+
child_indexes = std::move(save_indices);
67636763
} else if (field_name == name) {
67646764
// We have to add on the number of base classes to this index!
67656765
child_indexes.push_back(
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CXX_SOURCES := main.cpp
2+
3+
include Makefile.rules
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
Test handling of Anonymous Structs, especially that they don't crash lldb.
3+
"""
4+
5+
6+
import lldb
7+
import lldbsuite.test.lldbutil as lldbutil
8+
from lldbsuite.test.decorators import *
9+
from lldbsuite.test.lldbtest import *
10+
import os
11+
import shutil
12+
import time
13+
14+
15+
class TestFrameVarAnonStruct(TestBase):
16+
# If your test case doesn't stress debug info, then
17+
# set this to true. That way it won't be run once for
18+
# each debug info format.
19+
NO_DEBUG_INFO_TESTCASE = True
20+
21+
def test_frame_var(self):
22+
self.build()
23+
self.do_test()
24+
25+
def do_test(self):
26+
target = self.createTestTarget()
27+
28+
# Verify that we don't crash in this case.
29+
self.expect(
30+
"target variable 'b.x'",
31+
error=True,
32+
substrs=["can't find global variable 'b.x'"],
33+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct A {
2+
struct {
3+
int x = 1;
4+
};
5+
} a;
6+
7+
struct B {
8+
// Anonymous struct inherits another struct.
9+
struct : public A {
10+
int z = 3;
11+
};
12+
} b;
13+
14+
int main(int argc, char **argv) { return 0; }

0 commit comments

Comments
 (0)