[Pkg-bitcoin-commits] [libunivalue] 20/76: Stop parsing JSON after first finished construct.
Jonas Smedegaard
dr at jones.dk
Mon Apr 4 09:18:28 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 c8dcb7a6ded0362cced7d8b3e66ae6f12c4cb09d
Author: Jonas Schnelli <jonas.schnelli at include7.ch>
Date: Fri Sep 4 16:22:43 2015 +0200
Stop parsing JSON after first finished construct.
Sync from downstream: https://github.com/bitcoin/bitcoin/pull/6576/files
Created by / Credits: Daniel Kraft / domob1812
---
Makefile.am | 1 +
fail34.json | 1 +
unitester.cpp | 1 +
univalue_read.cpp | 14 ++++++++------
4 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 01f41b8..6241ef3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -50,6 +50,7 @@ EXTRA_DIST = \
fail31.json \
fail32.json \
fail33.json \
+ fail34.json \
fail3.json \
fail4.json \
fail5.json \
diff --git a/fail34.json b/fail34.json
new file mode 100644
index 0000000..3f8be17
--- /dev/null
+++ b/fail34.json
@@ -0,0 +1 @@
+{} garbage
\ No newline at end of file
diff --git a/unitester.cpp b/unitester.cpp
index ce40e3c..835556e 100644
--- a/unitester.cpp
+++ b/unitester.cpp
@@ -91,6 +91,7 @@ static const char *filenames[] = {
"fail31.json",
"fail32.json",
"fail33.json",
+ "fail34.json",
"fail3.json",
"fail4.json", // extra comma
"fail5.json",
diff --git a/univalue_read.cpp b/univalue_read.cpp
index 2617718..6459123 100644
--- a/univalue_read.cpp
+++ b/univalue_read.cpp
@@ -244,16 +244,16 @@ bool UniValue::read(const char *raw)
bool expectColon = false;
vector<UniValue*> stack;
+ string tokenVal;
+ unsigned int consumed;
enum jtokentype tok = JTOK_NONE;
enum jtokentype last_tok = JTOK_NONE;
- while (1) {
+ do {
last_tok = tok;
- string tokenVal;
- unsigned int consumed;
tok = getJsonToken(tokenVal, consumed, raw);
if (tok == JTOK_NONE || tok == JTOK_ERR)
- break;
+ return false;
raw += consumed;
switch (tok) {
@@ -377,9 +377,11 @@ bool UniValue::read(const char *raw)
default:
return false;
}
- }
+ } while (!stack.empty ());
- if (stack.size() != 0)
+ /* Check that nothing follows the initial construct (parsed above). */
+ tok = getJsonToken(tokenVal, consumed, raw);
+ if (tok != JTOK_NONE)
return false;
return true;
--
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