From 00382fa85126edc63720480fd22458e1af4e58c7 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 6 Dec 2018 13:17:43 +0100 Subject: json: Fix to reject duplicate object member names The JSON parser happily accepts duplicate object member names. The last value wins. Reproducer #1: $ qemu-system-x86_64 -qmp stdio {"QMP": {"version": {"qemu": {"micro": 93, "minor": 0, "major": 3}, "package": "v3.1.0-rc3-7-g87a45d86ed"}, "capabilities": []}} {'execute':'qmp_capabilities'} {"return": {}} {'execute':'blockdev-add','arguments':{'driver':'null-co', 'node-name':'foo','node-name':'bar'}} {"return": {}} {'execute':'query-named-block-nodes'} {"return": [{ [...] "node-name": "bar" [...] }]} Reproducer #2 is iotest 229. Fix the parser to reject duplicates, and fix iotest 229 not to use them. Reported-by: Max Reitz Signed-off-by: Markus Armbruster Message-Id: <20181206121743.20762-1-armbru@redhat.com> Reviewed-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé [Trailing whitespace tidied up] Signed-off-by: Markus Armbruster --- qobject/json-parser.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'qobject') diff --git a/qobject/json-parser.c b/qobject/json-parser.c index 5a840dfd86..7a7ae9e8d1 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -288,6 +288,11 @@ static int parse_pair(JSONParserContext *ctxt, QDict *dict) goto out; } + if (qdict_haskey(dict, qstring_get_str(key))) { + parse_error(ctxt, token, "duplicate key"); + goto out; + } + qdict_put_obj(dict, qstring_get_str(key), value); qobject_unref(key); -- cgit v1.2.3-55-g7522