[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v16 09/24] qom: Wrap prop visit in visit_start_struc
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH v16 09/24] qom: Wrap prop visit in visit_start_struct |
Date: |
Thu, 28 Apr 2016 15:45:17 -0600 |
The qmp-input visitor was allowing callers to play rather fast
and loose: when visiting a QDict, you could grab members of the
root dictionary without first pushing into the dict; the final
such culprit was the QOM code for converting to and from object
properties. But we are about to tighten the input visitor, at
which point user_creatable_add_type() as called with a QMP input
visitor via qmp_object_add() MUST follow the same paradigms as
everyone else, of pushing into the struct before grabbing its
keys.
The use of 'err ? NULL : &err' is temporary; a later patch will
clean that up when it splits visit_end_struct().
Furthermore, note that both callers always pass qdict, so we can
convert the conditional into an assert and reduce indentation.
The change has no impact to the testsuite now, but is required to
avoid a failure in tests/test-netfilter once qmp-input is made
stricter to detect inconsistent 'name' arguments on the root visit.
Since user_creatable_add_type() is also called with OptsVisitor
through user_creatable_add_opts(), we must also check that there
is no negative impact there; both pre- and post-patch, we see:
$ ./x86_64-softmmu/qemu-system-x86_64 -nographic -nodefaults -qmp stdio -object
secret,id=sec0,data=letmein,format=raw,foo=bar
qemu-system-x86_64: -object secret,id=sec0,data=letmein,format=raw,foo=bar:
Property '.foo' not found
That is, the only new checking that the new visit_end_struct() can
perform is for excess input, but we already catch excess input
earlier in object_property_set().
Signed-off-by: Eric Blake <address@hidden>
---
v16: turn qdict conditional into assertion
v15: hoist earlier in series, improve commit message
v14: no change
v13: no change
v12: new patch
---
qom/object_interfaces.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index 3931890..cad5542 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -118,15 +118,22 @@ Object *user_creatable_add_type(const char *type, const
char *id,
return NULL;
}
+ assert(qdict);
obj = object_new(type);
- if (qdict) {
- for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
- object_property_set(obj, v, e->key, &local_err);
- if (local_err) {
- goto out;
- }
+ visit_start_struct(v, NULL, NULL, 0, &local_err);
+ if (local_err) {
+ goto out;
+ }
+ for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
+ object_property_set(obj, v, e->key, &local_err);
+ if (local_err) {
+ break;
}
}
+ visit_end_struct(v, local_err ? NULL : &local_err);
+ if (local_err) {
+ goto out;
+ }
object_property_add_child(object_get_objects_root(),
id, obj, &local_err);
--
2.5.5
- [Qemu-devel] [PATCH v16 08/24] qapi-commands: Wrap argument visit in visit_start_struct, (continued)
[Qemu-devel] [PATCH v16 17/24] qmp: Add qmp_output_visitor_reset(), Eric Blake, 2016/04/28
[Qemu-devel] [PATCH v16 05/24] qapi: Consolidate QMP input visitor creation, Eric Blake, 2016/04/28
[Qemu-devel] [PATCH v16 09/24] qom: Wrap prop visit in visit_start_struct,
Eric Blake <=
[Qemu-devel] [PATCH v16 11/24] qmp-input: Refactor when list is advanced, Eric Blake, 2016/04/28
[Qemu-devel] [PATCH v16 07/24] qmp-input: Don't consume input when checking has_member, Eric Blake, 2016/04/28
[Qemu-devel] [PATCH v16 10/24] qmp-input: Require struct push to visit members of top dict, Eric Blake, 2016/04/28
[Qemu-devel] [PATCH v16 01/24] qapi-visit: Add visitor.type classification, Eric Blake, 2016/04/28
[Qemu-devel] [PATCH v16 06/24] qapi: Use strict QMP input visitor in more places, Eric Blake, 2016/04/28
[Qemu-devel] [PATCH v16 13/24] tests: Add check-qnull, Eric Blake, 2016/04/28
[Qemu-devel] [PATCH v16 14/24] qapi: Add visit_type_null() visitor, Eric Blake, 2016/04/28