Fix bug 20125 - clang-format segfaults on bad config.

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
This commit is contained in:
Rafael Espindola 2014-08-08 13:58:00 +00:00
parent 1952807c9c
commit 82acfbfe86
2 changed files with 13 additions and 1 deletions

View File

@ -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()) {

View File

@ -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
//