[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.

(cherry picked from commit 56778b7209)
This commit is contained in:
Steven Wu
2025-04-10 12:44:30 -07:00
parent c5b9a37107
commit 5ced9bd1e4

View File

@@ -115,8 +115,10 @@ void swift::BlockListStore::Implementation::addConfigureFilePath(StringRef path)
SM.getLLVMSourceMgr());
for (auto DI = Stream.begin(); DI != Stream.end(); ++ DI) {
assert(DI != Stream.end() && "Failed to read a document");
yaml::Node *N = DI->getRoot();
for (auto &pair: *dyn_cast<yaml::MappingNode>(N)) {
auto *MapNode = dyn_cast<yaml::MappingNode>(DI->getRoot());
if (!MapNode)
continue;
for (auto &pair: *MapNode) {
std::string key = getScalaString(pair.getKey());
auto action = llvm::StringSwitch<BlockListAction>(key)
#define BLOCKLIST_ACTION(X) .Case(#X, BlockListAction::X)