qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 09/23] qom: Wrap prop visit in visit_start_struct
Date: Thu, 12 May 2016 09:58:56 +0200	[thread overview]
Message-ID: <1463039950-4021-10-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1463039950-4021-1-git-send-email-armbru@redhat.com>

From: Eric Blake <eblake@redhat.com>

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 <eblake@redhat.com>
Message-Id: <1461879932-9020-10-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 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

  parent reply	other threads:[~2016-05-12  7:59 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-12  7:58 [Qemu-devel] [PULL 00/23] QAPI patches for 2016-05-12 Markus Armbruster
2016-05-12  7:58 ` [Qemu-devel] [PULL 01/23] qapi-visit: Add visitor.type classification Markus Armbruster
2016-05-12  7:58 ` [Qemu-devel] [PULL 02/23] qapi: Guarantee NULL obj on input visitor callback error Markus Armbruster
2016-05-12  7:58 ` [Qemu-devel] [PULL 03/23] qmp: Drop dead command->type Markus Armbruster
2016-05-12  7:58 ` [Qemu-devel] [PULL 04/23] qmp-input: Clean up stack handling Markus Armbruster
2016-05-12  7:58 ` [Qemu-devel] [PULL 05/23] qapi: Consolidate QMP input visitor creation Markus Armbruster
2016-05-12  7:58 ` [Qemu-devel] [PULL 06/23] qapi: Use strict QMP input visitor in more places Markus Armbruster
2016-05-12  7:58 ` [Qemu-devel] [PULL 07/23] qmp-input: Don't consume input when checking has_member Markus Armbruster
2016-05-12  7:58 ` [Qemu-devel] [PULL 08/23] qapi-commands: Wrap argument visit in visit_start_struct Markus Armbruster
2016-05-12  7:58 ` Markus Armbruster [this message]
2016-05-12  7:58 ` [Qemu-devel] [PULL 10/23] qmp-input: Require struct push to visit members of top dict Markus Armbruster
2016-05-12  7:58 ` [Qemu-devel] [PULL 11/23] qmp-input: Refactor when list is advanced Markus Armbruster
2016-05-12  7:58 ` [Qemu-devel] [PULL 12/23] qapi: Document visitor interfaces, add assertions Markus Armbruster
2016-05-12  7:59 ` [Qemu-devel] [PULL 13/23] tests: Add check-qnull Markus Armbruster
2016-05-12  7:59 ` [Qemu-devel] [PULL 14/23] qapi: Add visit_type_null() visitor Markus Armbruster
2016-05-12  7:59 ` [Qemu-devel] [PULL 15/23] qmp: Support explicit null during visits Markus Armbruster
2016-05-12  7:59 ` [Qemu-devel] [PULL 16/23] spapr_drc: Expose 'null' in qom-get when there is no fdt Markus Armbruster
2016-05-12  7:59 ` [Qemu-devel] [PULL 17/23] qmp: Don't reuse qmp visitor after grabbing output Markus Armbruster
2016-05-12  7:59 ` [Qemu-devel] [PULL 18/23] qmp: Tighten output visitor rules Markus Armbruster
2016-05-12  7:59 ` [Qemu-devel] [PULL 19/23] qapi: Split visit_end_struct() into pieces Markus Armbruster
2016-05-12  7:59 ` [Qemu-devel] [PULL 20/23] tests/string-input-visitor: Add negative integer tests Markus Armbruster
2016-05-12  7:59 ` [Qemu-devel] [PULL 21/23] qapi: Fix string input visitor handling of invalid list Markus Armbruster
2016-05-12  7:59 ` [Qemu-devel] [PULL 22/23] qapi: Simplify semantics of visit_next_list() Markus Armbruster
2016-05-12  7:59 ` [Qemu-devel] [PULL 23/23] qapi: Change visit_type_FOO() to no longer return partial objects Markus Armbruster
2016-05-12 14:55 ` [Qemu-devel] [PULL 00/23] QAPI patches for 2016-05-12 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1463039950-4021-10-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).