diff --git a/Makefile.am b/Makefile.am index 532fa1949dc..a8e08557901 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/lib/univalue_read.cpp b/lib/univalue_read.cpp index 7a9acdd75fd..2bd83238b48 100644 --- a/lib/univalue_read.cpp +++ b/lib/univalue_read.cpp @@ -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 == '\\') { diff --git a/test/fail44.json b/test/fail44.json new file mode 100644 index 00000000000..80edceddf1e --- /dev/null +++ b/test/fail44.json @@ -0,0 +1 @@ +"This file ends without a newline or close-quote. \ No newline at end of file diff --git a/test/unitester.cpp b/test/unitester.cpp index aa6f91c1b2f..2c37794a4bd 100644 --- a/test/unitester.cpp +++ b/test/unitester.cpp @@ -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",