Skip to content

Commit ac385ca

Browse files
Thomas Finchdonhinton
authored andcommitted
Fix null dereference in yaml::Document::skip
Summary: The attached test case replicates a null dereference crash in `yaml::Document::skip()`. This was fixed by adding a check and early return in the method. Reviewers: Bigcheese, hintonda, beanz Reviewed By: hintonda Subscribers: hiraditya, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69974
1 parent 6ebec32 commit ac385ca

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

llvm/lib/Support/YAMLParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,8 +2288,8 @@ Document::Document(Stream &S) : stream(S), Root(nullptr) {
22882288
bool Document::skip() {
22892289
if (stream.scanner->failed())
22902290
return false;
2291-
if (!Root)
2292-
getRoot();
2291+
if (!Root && !getRoot())
2292+
return false;
22932293
Root->skip();
22942294
Token &T = peekNext();
22952295
if (T.Kind == Token::TK_StreamEnd)

llvm/unittests/Support/YAMLParserTest.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,15 @@ TEST(YAMLParser, DifferentNodesIteratorOperatorEquals) {
331331
EXPECT_TRUE(End == AnotherEnd);
332332
}
333333

334+
TEST(YAMLParser, FlowSequenceTokensOutsideFlowSequence) {
335+
auto FlowSequenceStrs = {",", "]", "}"};
336+
SourceMgr SM;
337+
338+
for (auto &Str : FlowSequenceStrs) {
339+
yaml::Stream Stream(Str, SM);
340+
yaml::Document &Doc = *Stream.begin();
341+
EXPECT_FALSE(Doc.skip());
342+
}
343+
}
344+
334345
} // end namespace llvm

0 commit comments

Comments
 (0)