From: Eric Blake <eblake@redhat.com>
To: Markus Armbruster <armbru@redhat.com>, qemu-devel@nongnu.org
Cc: "Anthony Liguori" <aliguori@us.ibm.com>,
"Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH for-2.4 2/2] qom: Fix invalid error check in property_get_str()
Date: Mon, 20 Jul 2015 09:20:22 -0600 [thread overview]
Message-ID: <55AD11B6.1070700@redhat.com> (raw)
In-Reply-To: <1435765624-18404-3-git-send-email-armbru@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1919 bytes --]
On 07/01/2015 09:47 AM, Markus Armbruster wrote:
> 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(-)
>
Reviewed-by: Eric Blake <eblake@redhat.com>
> 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,
>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
prev parent reply other threads:[~2015-07-20 15:20 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 ` [Qemu-devel] [PATCH for-2.4 2/2] qom: Fix invalid error check in property_get_str() Markus Armbruster
2015-07-20 15:20 ` Eric Blake [this message]
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=55AD11B6.1070700@redhat.com \
--to=eblake@redhat.com \
--cc=afaerber@suse.de \
--cc=aliguori@us.ibm.com \
--cc=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).