Skip to content

[lldb] Defend against infinite recursion in GetClassDescriptor #145396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1505,15 +1505,24 @@ AppleObjCRuntimeV2::GetClassDescriptorFromISA(ObjCISA isa) {

ObjCLanguageRuntime::ClassDescriptorSP
AppleObjCRuntimeV2::GetClassDescriptor(ValueObject &valobj) {
ValueObjectSet seen;
return GetClassDescriptorImpl(valobj, seen);
}

ObjCLanguageRuntime::ClassDescriptorSP
AppleObjCRuntimeV2::GetClassDescriptorImpl(ValueObject &valobj,
ValueObjectSet &seen) {
seen.insert(&valobj);

ClassDescriptorSP objc_class_sp;
if (valobj.IsBaseClass()) {
ValueObject *parent = valobj.GetParent();
// if I am my own parent, bail out of here fast..
if (parent && parent != &valobj) {
ClassDescriptorSP parent_descriptor_sp = GetClassDescriptor(*parent);
if (parent_descriptor_sp)
return parent_descriptor_sp->GetSuperclass();
}
// Fail if there's a cycle in our parent chain.
if (!parent || seen.count(parent))
return nullptr;
if (ClassDescriptorSP parent_descriptor_sp =
GetClassDescriptorImpl(*parent, seen))
return parent_descriptor_sp->GetSuperclass();
return nullptr;
}
// if we get an invalid VO (which might still happen when playing around with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h"

#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/SmallSet.h"

class RemoteNXMapTable;

Expand Down Expand Up @@ -421,6 +422,10 @@ class AppleObjCRuntimeV2 : public AppleObjCRuntime {

lldb::addr_t GetISAHashTablePointer();

using ValueObjectSet = llvm::SmallPtrSet<ValueObject *, 8>;
ClassDescriptorSP GetClassDescriptorImpl(ValueObject &valobj,
ValueObjectSet &seen);

/// Update the generation count of realized classes. This is not an exact
/// count but rather a value that is incremented when new classes are realized
/// or destroyed. Unlike the count in gdb_objc_realized_classes, it will
Expand Down
Loading