[llvm] r236669 - YAML: Fix crash in the skip method of KeyValueNode class.

Alex Lorenz arphaman at gmail.com
Wed May 6 16:21:29 PDT 2015


Author: arphaman
Date: Wed May  6 18:21:29 2015
New Revision: 236669

URL: http://llvm.org/viewvc/llvm-project?rev=236669&view=rev
Log:
YAML: Fix crash in the skip method of KeyValueNode class. 

This commit changes the 'skip' method in the 'KeyValueNode' class
to ensure that it doesn't dereference a null pointer when calling 
the 'skip' method of its value child node. It also adds a unittest
that ensures that the crash doesn't occur.

This change is motivated by a patch that implements parsing
of YAML block scalars (http://reviews.llvm.org/D9503), as one
of the unittests in that patch triggered this problem.

Modified:
    llvm/trunk/include/llvm/Support/YAMLParser.h
    llvm/trunk/unittests/Support/YAMLParserTest.cpp

Modified: llvm/trunk/include/llvm/Support/YAMLParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/YAMLParser.h?rev=236669&r1=236668&r2=236669&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/YAMLParser.h (original)
+++ llvm/trunk/include/llvm/Support/YAMLParser.h Wed May  6 18:21:29 2015
@@ -253,7 +253,8 @@ public:
 
   void skip() override {
     getKey()->skip();
-    getValue()->skip();
+    if (Node *Val = getValue())
+      Val->skip();
   }
 
   static inline bool classof(const Node *N) {

Modified: llvm/trunk/unittests/Support/YAMLParserTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/YAMLParserTest.cpp?rev=236669&r1=236668&r2=236669&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/YAMLParserTest.cpp (original)
+++ llvm/trunk/unittests/Support/YAMLParserTest.cpp Wed May  6 18:21:29 2015
@@ -141,6 +141,10 @@ TEST(YAMLParser, HandlesEndOfFileGracefu
   ExpectParseError("In object hitting EOF", "{\"\"");
 }
 
+TEST(YAMLParser, HandlesNullValuesInKeyValueNodesGracefully) {
+  ExpectParseError("KeyValueNode with null value", "test: '");
+}
+
 // Checks that the given string can be parsed into an identical string inside
 // of an array.
 static void ExpectCanParseString(StringRef String) {





More information about the llvm-commits mailing list