[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 11/32] json: Fix to reject duplicate object member na
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PULL 11/32] json: Fix to reject duplicate object member names |
Date: |
Thu, 13 Dec 2018 19:43:19 +0100 |
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 <address@hidden>
Signed-off-by: Markus Armbruster <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Daniel P. Berrangé <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
[Trailing whitespace tidied up]
Signed-off-by: Markus Armbruster <address@hidden>
---
qobject/json-parser.c | 5 +++++
tests/qemu-iotests/229 | 1 -
2 files changed, 5 insertions(+), 1 deletion(-)
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);
diff --git a/tests/qemu-iotests/229 b/tests/qemu-iotests/229
index 86602437ff..893d098ad2 100755
--- a/tests/qemu-iotests/229
+++ b/tests/qemu-iotests/229
@@ -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',
--
2.17.2
- [Qemu-devel] [PULL 19/32] qapi: improve reporting of unknown or missing keys, (continued)
- [Qemu-devel] [PULL 19/32] qapi: improve reporting of unknown or missing keys, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 30/32] qapi: add condition to variants documentation, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 14/32] qapi: break long lines at 'data' member, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 21/32] qapi: add 'if' to enum members, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 01/32] cutils: Add qemu_strtod() and qemu_strtod_finite(), Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 09/32] test-string-input-visitor: Add range overflow tests, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 32/32] qapi: add conditions to REPLICATION type/commands on the schema, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 26/32] qapi: add 'if' to alternate members, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 20/32] qapi: add a dictionary form with 'name' key for enum members, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 25/32] qapi: add 'if' to union members, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 11/32] json: Fix to reject duplicate object member names,
Markus Armbruster <=
- [Qemu-devel] [PULL 29/32] qapi: add 'If:' condition to struct members documentation, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 16/32] qapi: change enum visitor and gen_enum* to take QAPISchemaMember, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 18/32] qapi: factor out checking for keys, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 24/32] qapi: Add 'if' to implicit struct members, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 22/32] qapi-events: add 'if' condition to implicit event enum, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 23/32] qapi: add a dictionary form for TYPE, Markus Armbruster, 2018/12/13
- Re: [Qemu-devel] [PULL 00/32] QAPI patches for 2018-12-13, Markus Armbruster, 2018/12/14