[Pkg-bitcoin-commits] [libunivalue] 70/76: parser: Ensure multiple values cannot follow each other

Jonas Smedegaard dr at jones.dk
Mon Apr 4 09:18:34 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libunivalue.

commit ccf35754f1a5d56e2a8f0d0c13c5be656b6bce6d
Author: Jeff Garzik <jeff at bloq.com>
Date:   Sat Nov 7 13:34:47 2015 -0500

    parser: Ensure multiple values cannot follow each other
    
    Fixes #15
---
 Makefile.am           |  1 +
 lib/univalue_read.cpp | 13 ++++++++++++-
 test/fail37.json      |  1 +
 test/unitester.cpp    |  3 ++-
 4 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 20cf523..3e9dc0f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -72,6 +72,7 @@ TEST_FILES = \
 	$(TEST_DATA_DIR)/fail34.json \
 	$(TEST_DATA_DIR)/fail35.json \
 	$(TEST_DATA_DIR)/fail36.json \
+	$(TEST_DATA_DIR)/fail37.json \
 	$(TEST_DATA_DIR)/fail3.json \
 	$(TEST_DATA_DIR)/fail4.json \
 	$(TEST_DATA_DIR)/fail5.json \
diff --git a/lib/univalue_read.cpp b/lib/univalue_read.cpp
index 6b956c3..c7516b9 100644
--- a/lib/univalue_read.cpp
+++ b/lib/univalue_read.cpp
@@ -244,8 +244,9 @@ enum jtokentype getJsonToken(string& tokenVal, unsigned int& consumed,
 enum expect_bits {
     EXP_OBJ_NAME = (1U << 0),
     EXP_COLON = (1U << 1),
-    EXP_VALUE = (1U << 3),
     EXP_ARR_VALUE = (1U << 2),
+    EXP_VALUE = (1U << 3),
+    EXP_NOT_VALUE = (1U << 4),
 };
 
 #define expect(bit) (expectMask & (EXP_##bit))
@@ -300,6 +301,12 @@ bool UniValue::read(const char *raw)
             return false;
         }
 
+        if (expect(NOT_VALUE)) {
+            if (isValueOpen)
+                return false;
+            clearExpect(NOT_VALUE);
+        }
+
         switch (tok) {
 
         case JTOK_OBJ_OPEN:
@@ -339,6 +346,7 @@ bool UniValue::read(const char *raw)
 
             stack.pop_back();
             clearExpect(OBJ_NAME);
+            setExpect(NOT_VALUE);
             break;
             }
 
@@ -390,6 +398,7 @@ bool UniValue::read(const char *raw)
             UniValue *top = stack.back();
             top->values.push_back(tmpVal);
 
+            setExpect(NOT_VALUE);
             break;
             }
 
@@ -401,6 +410,7 @@ bool UniValue::read(const char *raw)
             UniValue *top = stack.back();
             top->values.push_back(tmpVal);
 
+            setExpect(NOT_VALUE);
             break;
             }
 
@@ -419,6 +429,7 @@ bool UniValue::read(const char *raw)
                 top->values.push_back(tmpVal);
             }
 
+            setExpect(NOT_VALUE);
             break;
             }
 
diff --git a/test/fail37.json b/test/fail37.json
new file mode 100644
index 0000000..3294dc3
--- /dev/null
+++ b/test/fail37.json
@@ -0,0 +1 @@
+{"a":1 "b":2}
diff --git a/test/unitester.cpp b/test/unitester.cpp
index 5833107..fc2f078 100644
--- a/test/unitester.cpp
+++ b/test/unitester.cpp
@@ -93,8 +93,9 @@ static const char *filenames[] = {
         "fail32.json",
         "fail33.json",
         "fail34.json",
-        // "fail35.json",		// investigate - issue #15
+        "fail35.json",
         "fail36.json",
+        "fail37.json",
         "fail3.json",
         "fail4.json",                // extra comma
         "fail5.json",

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bitcoin/libunivalue.git



More information about the Pkg-bitcoin-commits mailing list