Skip to content

Commit 9b7201e

Browse files
committed
Add missing checks for nullptr.
We got crash reports from LLDB where protocolList is a nullptr when demangling a symbolic reference. While we're also investigating the root cause of the issue, the code in MetadataReader should also not just crash with such input. rdar://122698966
1 parent 5ce824f commit 9b7201e

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

include/swift/Remote/MetadataReader.h

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -527,15 +527,25 @@ class MetadataReader {
527527
// Dig out the protocol from the protocol list.
528528
auto protocolList = readMangledName(resolved.getResolvedAddress(),
529529
MangledNameKind::Type, dem);
530-
assert(protocolList->getFirstChild()
531-
->getFirstChild()
532-
->getFirstChild()
533-
->getFirstChild()
534-
->getKind() == Node::Kind::Protocol);
535-
auto protocol = protocolList->getFirstChild()
536-
->getFirstChild()
537-
->getFirstChild()
538-
->getFirstChild();
530+
assert(!protocolList || !protocolList->getNumChildren());
531+
if (!protocolList || !protocolList->getNumChildren())
532+
return nullptr;
533+
auto child = !protocolList->getFirstChild();
534+
assert(!child || !child->getNumChildren());
535+
if (!child || !child->getNumChildren())
536+
return nullptr;
537+
child = child->getFirstChild();
538+
assert(!child || !child->getNumChildren());
539+
if (!child || !child->getNumChildren())
540+
return nullptr;
541+
assert(!child || !child->getNumChildren());
542+
child = child->getFirstChild();
543+
if (!child || !child->getNumChildren())
544+
return nullptr;
545+
child = child->getFirstChild();
546+
if (!child || !child->getKind() == Node::Kind::Protocol)
547+
return nullptr;
548+
auto protocol = child;
539549
auto protocolType = dem.createNode(Node::Kind::Type);
540550
protocolType->addChild(protocol, dem);
541551
return protocolType;

0 commit comments

Comments
 (0)