Skip to content

Commit

Permalink
json: Fix to reject duplicate object member names
Browse files Browse the repository at this point in the history
The JSON parser happily accepts duplicate object member names.  The
last value wins.  Reproducer TrungNguyen1909#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 TrungNguyen1909#2 is iotest 229.

Fix the parser to reject duplicates, and fix iotest 229 not to use
them.

Reported-by: Max Reitz <[email protected]>
Signed-off-by: Markus Armbruster <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Daniel P. Berrangé <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
[Trailing whitespace tidied up]
Signed-off-by: Markus Armbruster <[email protected]>
  • Loading branch information
Markus Armbruster committed Dec 13, 2018
1 parent aee03bf commit 00382fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 5 additions & 0 deletions qobject/json-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion tests/qemu-iotests/229
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ echo
_send_qemu_cmd $QEMU_HANDLE \
"{'execute': 'drive-mirror',
'arguments': {'device': 'testdisk',
'mode': 'absolute-paths',
'format': '$IMGFMT',
'target': '$DEST_IMG',
'sync': 'full',
Expand Down

0 comments on commit 00382fa

Please sign in to comment.