提交 c5d39274 编写于 作者: J Ján Tomko

Error out on unterminated arrays and objects in JSON parser

上级 251521c7
......@@ -1004,7 +1004,14 @@ virJSONValuePtr virJSONValueFromString(const char *jsonstring)
goto cleanup;
}
ret = parser.head;
if (parser.nstate != 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse json %s: unterminated string/map/array"),
jsonstring);
virJSONValueFree(parser.head);
} else {
ret = parser.head;
}
cleanup:
yajl_free(hand);
......
......@@ -203,10 +203,16 @@ mymain(void)
DO_TEST_PARSE_FAIL("float with garbage", "[ 0.0314159ee+100 ]");
DO_TEST_PARSE("string", "[ \"The meaning of life\" ]");
DO_TEST_PARSE_FAIL("unterminated string", "[ \"The meaning of lif ]");
DO_TEST_PARSE_FAIL("object with numeric keys", "{ 1:1, 2:1, 3:2 }");
DO_TEST_PARSE_FAIL("unterminated object", "{ \"1\":1, \"2\":1, \"3\":2");
DO_TEST_PARSE_FAIL("unterminated array of objects",
"[ {\"name\": \"John\"}, {\"name\": \"Paul\"}, ");
DO_TEST_PARSE_FAIL("array of an object with an array as a key",
"[ {[\"key1\", \"key2\"]: \"value\"} ]");
DO_TEST_PARSE_FAIL("object with unterminated key", "{ \"key:7 }");
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册