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

The problem was in unchecked dyn_cast inside of Input::createHNodes.
Patch by Roman Kashitsyn!

llvm-svn: 215205
This commit is contained in:
Rafael Espindola 2014-08-08 13:58:00 +00:00
parent 9c70c83628
commit 0c2eeeddf1
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
//