[PATCH] D61608: Fix YAML parser's Document::skip for null nodes

Thomas Finch via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 10 14:44:01 PDT 2019


thomasfinch updated this revision to Diff 203901.
thomasfinch added a comment.

Move error checking to Document::parseBlockNode, make sure Document::skip doesn't crash if getRoot returns null.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61608/new/

https://reviews.llvm.org/D61608

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


Index: llvm/unittests/Support/YAMLParserTest.cpp
===================================================================
--- llvm/unittests/Support/YAMLParserTest.cpp
+++ llvm/unittests/Support/YAMLParserTest.cpp
@@ -331,4 +331,15 @@
   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
Index: llvm/lib/Support/YAMLParser.cpp
===================================================================
--- llvm/lib/Support/YAMLParser.cpp
+++ llvm/lib/Support/YAMLParser.cpp
@@ -2269,8 +2269,8 @@
 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)
@@ -2395,8 +2395,12 @@
     //       !!null null.
     return new (NodeAllocator) NullNode(stream.CurrentDoc);
   case Token::TK_Error:
+  case Token::TK_FlowEntry:
+  case Token::TK_FlowMappingEnd:
+  case Token::TK_FlowSequenceEnd: {
     return nullptr;
   }
+  }
   llvm_unreachable("Control flow shouldn't reach here.");
   return nullptr;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61608.203901.patch
Type: text/x-patch
Size: 1362 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190610/2ed87b06/attachment.bin>


More information about the llvm-commits mailing list