Skip to content

Commit

Permalink
Fix bug 20125 - clang-format segfaults on bad config.
Browse files Browse the repository at this point in the history
The problem was in unchecked dyn_cast inside of Input::createHNodes.
Patch by Roman Kashitsyn!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215205 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Aug 8, 2014
1 parent 1952807 commit 82acfbf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/Support/YAMLTraits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,12 @@ Input::HNode *Input::createHNodes(Node *N) {
} else if (MappingNode *Map = dyn_cast<MappingNode>(N)) {
MapHNode *mapHNode = new MapHNode(N);
for (KeyValueNode &KVN : *Map) {
ScalarNode *KeyScalar = dyn_cast<ScalarNode>(KVN.getKey());
Node *KeyNode = KVN.getKey();
ScalarNode *KeyScalar = dyn_cast<ScalarNode>(KeyNode);
if (!KeyScalar) {
setError(KeyNode, "Map key must be a scalar");
break;
}
StringStorage.clear();
StringRef KeyStr = KeyScalar->getValue(StringStorage);
if (!StringStorage.empty()) {
Expand Down
7 changes: 7 additions & 0 deletions unittests/Support/YAMLIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ TEST(YAMLIO, TestMapRead) {
}
}

TEST(YAMLIO, TestMalformedMapRead) {
FooBar doc;
Input yin("{foo: 3; bar: 5}", nullptr, suppressErrorMessages);
yin >> doc;
EXPECT_TRUE(!!yin.error());
}

//
// Test the reading of a yaml sequence of mappings
//
Expand Down

0 comments on commit 82acfbf

Please sign in to comment.