]> granicus.if.org Git - llvm/commitdiff
[YAMLParser] Don't crash on null keys in KeyValueNodes.
authorBenjamin Kramer <benny.kra@googlemail.com>
Thu, 23 Nov 2017 20:57:20 +0000 (20:57 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Thu, 23 Nov 2017 20:57:20 +0000 (20:57 +0000)
Found by clangd-fuzzer!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318935 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/YAMLParser.h
unittests/Support/YAMLParserTest.cpp

index 626507947a78434f2e4d8f4c592187cc25f8698c..859c2c1f7b33181dc1d017f02048010ee354ed8e 100644 (file)
@@ -291,9 +291,11 @@ public:
   Node *getValue();
 
   void skip() override {
-    getKey()->skip();
-    if (Node *Val = getValue())
-      Val->skip();
+    if (Node *Val = getKey()) {
+      Key->skip();
+      if (Node *Val = getValue())
+        Val->skip();
+    }
   }
 
   static bool classof(const Node *N) {
index d411a286830bb3ea9518e4977972bd0051388d77..7962f3ca1ad1cf3b02609d992773b47e1a31a33b 100644 (file)
@@ -180,6 +180,7 @@ TEST(YAMLParser, HandlesEndOfFileGracefully) {
 }
 
 TEST(YAMLParser, HandlesNullValuesInKeyValueNodesGracefully) {
+  ExpectParseError("KeyValueNode with null key", "? \"\n:");
   ExpectParseError("KeyValueNode with null value", "test: '");
 }