qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Anthony Liguori" <aliguori@us.ibm.com>,
	"Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] [PATCH for-2.4 2/2] qom: Fix invalid error check in property_get_str()
Date: Wed,  1 Jul 2015 17:47:04 +0200	[thread overview]
Message-ID: <1435765624-18404-3-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1435765624-18404-1-git-send-email-armbru@redhat.com>

When a function returns a null pointer on error and only on error, you
can do

    if (!foo(foos, errp)) {
        ... handle error ...
    }

instead of the more cumbersome

    Error *err = NULL;

    if (!foo(foos, &err)) {
        error_propagate(errp, err);
        ... handle error ...
    }

A StringProperty's getter, however, may return null on success!  We
then fail to call visit_type_str().

Screwed up in 6a146eb, v1.1.

Fails tests/qom-test in my current, heavily hacked QAPI branch.  No
reproducer for master known (but I didn't look hard).

Cc: Andreas Färber <afaerber@suse.de>
Cc: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 qom/object.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index 6173da8..4c4df55 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1591,14 +1591,18 @@ typedef struct StringProperty
 static void property_get_str(Object *obj, Visitor *v, void *opaque,
                              const char *name, Error **errp)
 {
+    Error *err = NULL;
     StringProperty *prop = opaque;
     char *value;
 
-    value = prop->get(obj, errp);
-    if (value) {
-        visit_type_str(v, &value, name, errp);
-        g_free(value);
+    value = prop->get(obj, &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
     }
+
+    visit_type_str(v, &value, name, errp);
+    g_free(value);
 }
 
 static void property_set_str(Object *obj, Visitor *v, void *opaque,
-- 
1.9.3

  parent reply	other threads:[~2015-07-01 15:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-01 15:47 [Qemu-devel] [PATCH for-2.4 0/2] qom: Fix misuse of Error API Markus Armbruster
2015-07-01 15:47 ` [Qemu-devel] [PATCH for-2.4 1/2] qom: Do not reuse errp after a possible error Markus Armbruster
2015-07-01 16:03   ` Daniel P. Berrange
2015-07-01 15:47 ` Markus Armbruster [this message]
2015-07-20 15:20   ` [Qemu-devel] [PATCH for-2.4 2/2] qom: Fix invalid error check in property_get_str() Eric Blake

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=1435765624-18404-3-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=afaerber@suse.de \
    --cc=aliguori@us.ibm.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).