From 01eb33b4cb50f5d120e045ed3cf47a562a6e0611 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Thu, 23 Nov 2017 20:57:20 +0000 Subject: [PATCH] [YAMLParser] Don't crash on null keys in KeyValueNodes. 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 | 8 +++++--- unittests/Support/YAMLParserTest.cpp | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/llvm/Support/YAMLParser.h b/include/llvm/Support/YAMLParser.h index 626507947a7..859c2c1f7b3 100644 --- a/include/llvm/Support/YAMLParser.h +++ b/include/llvm/Support/YAMLParser.h @@ -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) { diff --git a/unittests/Support/YAMLParserTest.cpp b/unittests/Support/YAMLParserTest.cpp index d411a286830..7962f3ca1ad 100644 --- a/unittests/Support/YAMLParserTest.cpp +++ b/unittests/Support/YAMLParserTest.cpp @@ -180,6 +180,7 @@ TEST(YAMLParser, HandlesEndOfFileGracefully) { } TEST(YAMLParser, HandlesNullValuesInKeyValueNodesGracefully) { + ExpectParseError("KeyValueNode with null key", "? \"\n:"); ExpectParseError("KeyValueNode with null value", "test: '"); } -- 2.50.1