https://github.com/cmtice created 
https://github.com/llvm/llvm-project/pull/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.

>From b8c64e227b8f9f82b420cc5c2f24fbd3f75f67f5 Mon Sep 17 00:00:00 2001
From: Caroline Tice <cmt...@google.com>
Date: Tue, 26 Nov 2024 15:08:32 -0800
Subject: [PATCH] [lLDB] Fix crash in
 TypeSystemClang::GetIndexofChildMemberWithName.

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.
---
 lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 1a77c7cf9161a0..16eca7700d9fff 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -6754,12 +6754,12 @@ size_t TypeSystemClang::GetIndexOfChildMemberWithName(
           llvm::StringRef field_name = field->getName();
           if (field_name.empty()) {
             CompilerType field_type = GetType(field->getType());
+            std::vector<uint32_t> save_indices = child_indexes;
             child_indexes.push_back(child_idx);
             if (field_type.GetIndexOfChildMemberWithName(
                     name, omit_empty_base_classes, child_indexes))
               return child_indexes.size();
-            child_indexes.pop_back();
-
+            child_indexes = save_indices;
           } else if (field_name == name) {
             // We have to add on the number of base classes to this index!
             child_indexes.push_back(

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to