Skip to content

[Runtime] Eliminate a use-after-free when comparing @objc type names. #21483

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
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
8 changes: 5 additions & 3 deletions stdlib/public/runtime/MetadataLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ _findNominalTypeDescriptor(Demangle::NodePointer node,
/// Find the context descriptor for the type extended by the given extension.
static const ContextDescriptor *
_findExtendedTypeContextDescriptor(const ExtensionContextDescriptor *extension,
Demangler &demangler,
Demangle::NodePointer *demangledNode
= nullptr) {
Demangle::NodePointer localNode;
Demangle::NodePointer &node = demangledNode ? *demangledNode : localNode;

auto mangledName = extension->getMangledExtendedContext();
auto demangler = getDemanglerForRuntimeTypeResolution();
node = demangler.demangleType(mangledName);
if (!node)
return nullptr;
Expand Down Expand Up @@ -423,7 +423,7 @@ swift::_contextDescriptorMatchesMangling(const ContextDescriptor *context,

Demangle::NodePointer extendedContextDemangled;
auto extendedDescriptorFromDemangled =
_findExtendedTypeContextDescriptor(extension,
_findExtendedTypeContextDescriptor(extension, demangler,
&extendedContextDemangled);

// Determine whether the contexts match.
Expand Down Expand Up @@ -822,8 +822,10 @@ bool swift::_gatherGenericParameterCounts(
std::vector<unsigned> &genericParamCounts) {
// If we have an extension descriptor, extract the extended type and use
// that.
auto demangler = getDemanglerForRuntimeTypeResolution();
if (auto extension = dyn_cast<ExtensionContextDescriptor>(descriptor)) {
if (auto extendedType = _findExtendedTypeContextDescriptor(extension))
if (auto extendedType =
_findExtendedTypeContextDescriptor(extension, demangler))
descriptor = extendedType;
}

Expand Down
1 change: 1 addition & 0 deletions test/Runtime/demangleToMetadataObjC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ DemangleToMetadataTests.test("synthesized declarations") {
}

DemangleToMetadataTests.test("members of runtime-only Objective-C classes") {
expectNotNil(_typeByName("So17OS_dispatch_queueC8DispatchE10AttributesV"))
expectEqual(DispatchQueue.Attributes.self,
_typeByName("So17OS_dispatch_queueC8DispatchE10AttributesV")!)
}
Expand Down