[llvm] ac385ca - Fix null dereference in yaml::Document::skip

Don Hinton via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 11 20:50:33 PST 2019


Author: Thomas Finch
Date: 2019-11-11T20:48:28-08:00
New Revision: ac385ca63fe8bc283d7f5be213319cc3b930b4cc

URL: https://github.com/llvm/llvm-project/commit/ac385ca63fe8bc283d7f5be213319cc3b930b4cc
DIFF: https://github.com/llvm/llvm-project/commit/ac385ca63fe8bc283d7f5be213319cc3b930b4cc.diff

LOG: 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

Added: 
    

Modified: 
    llvm/lib/Support/YAMLParser.cpp
    llvm/unittests/Support/YAMLParserTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/YAMLParser.cpp b/llvm/lib/Support/YAMLParser.cpp
index 333648dae2b9..d17e7b227f4a 100644
--- a/llvm/lib/Support/YAMLParser.cpp
+++ b/llvm/lib/Support/YAMLParser.cpp
@@ -2288,8 +2288,8 @@ Document::Document(Stream &S) : stream(S), Root(nullptr) {
 bool Document::skip()  {
   if (stream.scanner->failed())
     return false;
-  if (!Root)
-    getRoot();
+  if (!Root && !getRoot())
+    return false;
   Root->skip();
   Token &T = peekNext();
   if (T.Kind == Token::TK_StreamEnd)

diff  --git a/llvm/unittests/Support/YAMLParserTest.cpp b/llvm/unittests/Support/YAMLParserTest.cpp
index 06d4b0e269b9..938a6ab2a398 100644
--- a/llvm/unittests/Support/YAMLParserTest.cpp
+++ b/llvm/unittests/Support/YAMLParserTest.cpp
@@ -331,4 +331,15 @@ TEST(YAMLParser, DifferentNodesIteratorOperatorEquals) {
   EXPECT_TRUE(End == AnotherEnd);
 }
 
+TEST(YAMLParser, FlowSequenceTokensOutsideFlowSequence) {
+  auto FlowSequenceStrs = {",", "]", "}"};
+  SourceMgr SM;
+
+  for (auto &Str : FlowSequenceStrs) {
+    yaml::Stream Stream(Str, SM);
+    yaml::Document &Doc = *Stream.begin();
+    EXPECT_FALSE(Doc.skip());
+  }
+}
+
 } // end namespace llvm


        


More information about the llvm-commits mailing list