Skip to content

Commit

Permalink
[YAMLParser] Don't crash on null keys in KeyValueNodes.
Browse files Browse the repository at this point in the history
Found by clangd-fuzzer!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318935 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
d0k committed Nov 23, 2017
1 parent 6dce9fb commit 01eb33b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions include/llvm/Support/YAMLParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,11 @@ class KeyValueNode final : public Node {
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) {
Expand Down
1 change: 1 addition & 0 deletions unittests/Support/YAMLParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ TEST(YAMLParser, HandlesEndOfFileGracefully) {
}

TEST(YAMLParser, HandlesNullValuesInKeyValueNodesGracefully) {
ExpectParseError("KeyValueNode with null key", "? \"\n:");
ExpectParseError("KeyValueNode with null value", "test: '");
}

Expand Down

0 comments on commit 01eb33b

Please sign in to comment.