Skip to content

Commit

Permalink
Reject unterminated strings
Browse files Browse the repository at this point in the history
Fixes following test failures in https://github.com/nst/JSONTestSuite:

bitcoin SHOULD_HAVE_FAILED  n_string_single_doublequote.json
  • Loading branch information
ryanofsky committed Jan 29, 2017
1 parent a31231b commit 4fd5444
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ TEST_FILES = \
$(TEST_DATA_DIR)/fail40.json \
$(TEST_DATA_DIR)/fail41.json \
$(TEST_DATA_DIR)/fail42.json \
$(TEST_DATA_DIR)/fail44.json \
$(TEST_DATA_DIR)/fail3.json \
$(TEST_DATA_DIR)/fail4.json \
$(TEST_DATA_DIR)/fail5.json \
Expand Down
4 changes: 2 additions & 2 deletions lib/univalue_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ enum jtokentype getJsonToken(string& tokenVal, unsigned int& consumed,
string valStr;
JSONUTF8StringFilter writer(valStr);

while (raw < end) {
if ((unsigned char)*raw < 0x20)
while (true) {
if (raw >= end || (unsigned char)*raw < 0x20)
return JTOK_ERR;

else if (*raw == '\\') {
Expand Down
1 change: 1 addition & 0 deletions test/fail44.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"This file ends without a newline or close-quote.
1 change: 1 addition & 0 deletions test/unitester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ static const char *filenames[] = {
"fail40.json", // invalid unicode: broken UTF-8
"fail41.json", // invalid unicode: unfinished UTF-8
"fail42.json", // valid json with garbage following a nul byte
"fail44.json", // unterminated string
"fail3.json",
"fail4.json", // extra comma
"fail5.json",
Expand Down

0 comments on commit 4fd5444

Please sign in to comment.