Skip to content

Commit 56778b7

Browse files
[BlockList] Fix a crash if block is empty
Check if the root node is a mapping node before iterating. This fixes a crash when the YAML file is not the expected format.
1 parent 3490c73 commit 56778b7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/Basic/BlockList.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ void swift::BlockListStore::Implementation::addConfigureFilePath(StringRef path)
115115
SM.getLLVMSourceMgr());
116116
for (auto DI = Stream.begin(); DI != Stream.end(); ++ DI) {
117117
assert(DI != Stream.end() && "Failed to read a document");
118-
yaml::Node *N = DI->getRoot();
119-
for (auto &pair: *dyn_cast<yaml::MappingNode>(N)) {
118+
auto *MapNode = dyn_cast<yaml::MappingNode>(DI->getRoot());
119+
if (!MapNode)
120+
continue;
121+
for (auto &pair: *MapNode) {
120122
std::string key = getScalaString(pair.getKey());
121123
auto action = llvm::StringSwitch<BlockListAction>(key)
122124
#define BLOCKLIST_ACTION(X) .Case(#X, BlockListAction::X)

0 commit comments

Comments
 (0)