Skip to content

Commit 728abe9

Browse files
authored
Reflection Library crash inspecting certain BoundGeneric types (#32983)
* Reflectio Library crash inspecting certain BoundGeneric types If the parent of a BoundGeneric type is not a NominalType (for example, if the Parent was an ObjCClass type) the `getDepth()` method would end up reading a Parent reference from uninitialized memory. The resulting garbage pointer would cause a crash in the tool that was using the reflection library (leaks, instruments, etc.) Of course, this does not always result in a crash, since the memory in question is frequently zeroed, resulting in a nil pointer that is safely detected. Resolves rdar://54173375 * Fix compile
1 parent 868425b commit 728abe9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

stdlib/public/Reflection/TypeRef.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,11 +728,15 @@ bool TypeRef::isConcreteAfterSubstitutions(
728728

729729
unsigned NominalTypeTrait::getDepth() const {
730730
if (auto P = Parent) {
731-
if (auto *Nominal = dyn_cast<NominalTypeRef>(P))
732-
return 1 + Nominal->getDepth();
733-
return 1 + cast<BoundGenericTypeRef>(P)->getDepth();
731+
switch (P->getKind()) {
732+
case TypeRefKind::Nominal:
733+
return 1 + cast<NominalTypeRef>(P)->getDepth();
734+
case TypeRefKind::BoundGeneric:
735+
return 1 + cast<BoundGenericTypeRef>(P)->getDepth();
736+
default:
737+
break;
738+
}
734739
}
735-
736740
return 0;
737741
}
738742

0 commit comments

Comments
 (0)