Skip to content

Commit 4e2213d

Browse files
committed
Add nullptr checks before accessing children in getUnspecialized
The demangler already has an error mechanism to report if demangling failed. Add null pointer checks before every access in Demangle::getUnspecialized, and return an error if the child doesn't exist. rdar://110141007
1 parent 19094e3 commit 4e2213d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/Demangling/Remangler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3839,6 +3839,8 @@ ManglingErrorOr<NodePointer> Demangle::getUnspecialized(Node *node,
38393839
case Node::Kind::TypeAlias:
38403840
case Node::Kind::OtherNominalType: {
38413841
NodePointer result = Factory.createNode(node->getKind());
3842+
3843+
DEMANGLER_ASSERT(node->hasChildren(), node);
38423844
NodePointer parentOrModule = node->getChild(0);
38433845
if (isSpecialized(parentOrModule)) {
38443846
auto unspec = getUnspecialized(parentOrModule, Factory);
@@ -3859,21 +3861,25 @@ ManglingErrorOr<NodePointer> Demangle::getUnspecialized(Node *node,
38593861
case Node::Kind::BoundGenericProtocol:
38603862
case Node::Kind::BoundGenericOtherNominalType:
38613863
case Node::Kind::BoundGenericTypeAlias: {
3864+
DEMANGLER_ASSERT(node->hasChildren(), node);
38623865
NodePointer unboundType = node->getChild(0);
38633866
DEMANGLER_ASSERT(unboundType->getKind() == Node::Kind::Type, unboundType);
3867+
DEMANGLER_ASSERT(unboundType->hasChildren(), unboundType);
38643868
NodePointer nominalType = unboundType->getChild(0);
38653869
if (isSpecialized(nominalType))
38663870
return getUnspecialized(nominalType, Factory);
38673871
return nominalType;
38683872
}
38693873

38703874
case Node::Kind::ConstrainedExistential: {
3875+
DEMANGLER_ASSERT(node->hasChildren(), node);
38713876
NodePointer unboundType = node->getChild(0);
38723877
DEMANGLER_ASSERT(unboundType->getKind() == Node::Kind::Type, unboundType);
38733878
return unboundType;
38743879
}
38753880

38763881
case Node::Kind::BoundGenericFunction: {
3882+
DEMANGLER_ASSERT(node->hasChildren(), node);
38773883
NodePointer unboundFunction = node->getChild(0);
38783884
DEMANGLER_ASSERT(unboundFunction->getKind() == Node::Kind::Function ||
38793885
unboundFunction->getKind() ==
@@ -3885,6 +3891,7 @@ ManglingErrorOr<NodePointer> Demangle::getUnspecialized(Node *node,
38853891
}
38863892

38873893
case Node::Kind::Extension: {
3894+
DEMANGLER_ASSERT(node->getNumChildren() >= 2, node);
38883895
NodePointer parent = node->getChild(1);
38893896
if (!isSpecialized(parent))
38903897
return node;

0 commit comments

Comments
 (0)