提交 54dbba5b 编写于 作者: E Eric Blake 提交者: Michal Privoznik

json: reject javascript comments

We have been allowing javascript style comments in JSON ever
since commit 9428f2ce (v0.7.5), but qemu doesn't send them, and
they are not strict JSON.  Reject them for now; if we can later
prove that it is worthwhile, we can reinstate it at that point
(or even make it conditional, by adding a bool parameter to
the libvirt entry point).

* src/util/virjson.c (virJSONValueFromString): Don't enable
comment parsing.
* tests/jsontest.c (mymain): Test it.
Signed-off-by: NEric Blake <eblake@redhat.com>
上级 f2acaebd
......@@ -1596,7 +1596,7 @@ virJSONValueFromString(const char *jsonstring)
int rc;
size_t len = strlen(jsonstring);
# ifndef WITH_YAJL2
yajl_parser_config cfg = { 1, 1 };
yajl_parser_config cfg = { 0, 1 };
# endif
VIR_DEBUG("string=%s", jsonstring);
......@@ -1604,7 +1604,7 @@ virJSONValueFromString(const char *jsonstring)
# ifdef WITH_YAJL2
hand = yajl_alloc(&parserCallbacks, NULL, &parser);
if (hand) {
yajl_config(hand, yajl_allow_comments, 1);
yajl_config(hand, yajl_allow_comments, 0);
yajl_config(hand, yajl_dont_validate_strings, 0);
}
# else
......
......@@ -418,6 +418,7 @@ mymain(void)
DO_TEST_PARSE_FAIL("incomplete keyword", "tr");
DO_TEST_PARSE_FAIL("overdone keyword", "[ truest ]");
DO_TEST_PARSE_FAIL("unknown keyword", "huh");
DO_TEST_PARSE_FAIL("comments", "[ /* nope */\n1 // not this either\n]");
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");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册