All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: marcandre.lureau@gmail.com, qemu-devel@nongnu.org,
	Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH v2] qapi: Fix regression with '-netdev ?'
Date: Thu, 15 Oct 2015 08:24:17 +0200	[thread overview]
Message-ID: <87wpuoodim.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <1444861825-19256-1-git-send-email-eblake@redhat.com> (Eric Blake's message of "Wed, 14 Oct 2015 16:30:25 -0600")

Eric Blake <eblake@redhat.com> writes:

> Commit e36c714e causes 'qemu -netdev ?' to dump core, because the
> call to visit_end_union() is no longer conditional on whether
> *obj was allocated.
>
> Reported by Marc-André Lureau <marcandre.lureau@gmail.com>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
> v2: don't depend on unreleased patches
>
>  scripts/qapi-visit.py | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
> index 2a9fab8..d0759d7 100644
> --- a/scripts/qapi-visit.py
> +++ b/scripts/qapi-visit.py
> @@ -301,7 +301,9 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error
>  out_obj:
>      error_propagate(errp, err);
>      err = NULL;
> -    visit_end_union(v, !!(*obj)->data, &err);
> +    if (*obj) {
> +        visit_end_union(v, !!(*obj)->data, &err);
> +    }
>      error_propagate(errp, err);
>      err = NULL;
>      visit_end_struct(v, &err);

Let's see.

Before commit e36c714e, we generated

        visit_start_struct(v, (void **)obj, "%(name)s", name, sizeof(%(c_name)s), &err);
        if (err) {
            goto out;
        }
        if (*obj) {
    [...]
    out_obj:
            error_propagate(errp, err);
            err = NULL;
            visit_end_union(v, !!(*obj)->data, &err);
            error_propagate(errp, err);
            err = NULL;
        }
        visit_end_struct(v, &err);
    out:

Since then

        visit_start_struct(v, (void **)obj, "%(name)s", name, sizeof(%(c_name)s), &err);
        if (err) {
            goto out;
        }
        if (!*obj) {
            goto out_obj;       // goto out_end would've been faithful trafo
        }
        [...]
    out_obj:
        error_propagate(errp, err);                     //
        err = NULL;                                     // This code became
        visit_end_union(v, !!(*obj)->data, &err);       // accidentally
        error_propagate(errp, err);                     // unconditional
        err = NULL;                                     //
    // out_end:
        visit_end_struct(v, &err);
    out:
        error_propagate(errp, err);

We screwed up the if !*obj.  Instead of correcting the goto, you exploit
that err is null, and thus the accidentally unconditional code is a
no-op except for the visit_end_union(), so you protect that.  Okay.

In case anyone thinks correcting the goto would be nicer: the
visit_end_union() will go away soon.

I'll take this through my tree.  Expect a pull request today.  Thanks!

      reply	other threads:[~2015-10-15  6:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-14 22:30 [Qemu-devel] [PATCH v2] qapi: Fix regression with '-netdev ?' Eric Blake
2015-10-15  6:24 ` Markus Armbruster [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=87wpuoodim.fsf@blackfin.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=mdroth@linux.vnet.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.