Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

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
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
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
@@ -0,0 +1 @@
"This file ends without a newline or close-quote.
1 change: 1 addition & 0 deletions test/unitester.cpp
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.