diff options
author | Daniel Kraft <d@domob.eu> | 2015-08-20 12:48:43 +0200 |
---|---|---|
committer | Daniel Kraft <d@domob.eu> | 2015-08-20 12:48:43 +0200 |
commit | e938122b7ba8723c8cab6de78e8a9b39ad188589 (patch) | |
tree | 8dc918238e08377ef3ccac660f8fd935e562e31e /src/test/univalue_tests.cpp | |
parent | ef30389e2a4a83c2845a2cbdf3a7c2f062404077 (diff) |
Stop parsing JSON after first finished construct.
Fix https://github.com/bitcoin/bitcoin/issues/6558. In particular, stop
parsing JSON after the first object or array is finished. Check that no
other garbage follows, and fail the parser if it does.
Diffstat (limited to 'src/test/univalue_tests.cpp')
-rw-r--r-- | src/test/univalue_tests.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/test/univalue_tests.cpp b/src/test/univalue_tests.cpp index 67cb9b9623..ee31c0955b 100644 --- a/src/test/univalue_tests.cpp +++ b/src/test/univalue_tests.cpp @@ -314,6 +314,21 @@ BOOST_AUTO_TEST_CASE(univalue_readwrite) BOOST_CHECK(obj["key3"].isObject()); BOOST_CHECK_EQUAL(strJson1, v.write()); + + /* Check for (correctly reporting) a parsing error if the initial + JSON construct is followed by more stuff. Note that whitespace + is, of course, exempt. */ + + BOOST_CHECK(v.read(" {}\n ")); + BOOST_CHECK(v.isObject()); + BOOST_CHECK(v.read(" []\n ")); + BOOST_CHECK(v.isArray()); + + BOOST_CHECK(!v.read("@{}")); + BOOST_CHECK(!v.read("{} garbage")); + BOOST_CHECK(!v.read("[]{}")); + BOOST_CHECK(!v.read("{}[]")); + BOOST_CHECK(!v.read("{} 42")); } BOOST_AUTO_TEST_SUITE_END() |