From: Eric Blake <eblake@redhat.com>
To: Michael Roth <mdroth@linux.vnet.ibm.com>, qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, lcapitulino@redhat.com, famz@redhat.com,
qemu-stable@nongnu.org, armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 1/4] qapi: add visit_start_union and visit_end_union
Date: Wed, 17 Sep 2014 16:33:46 -0600 [thread overview]
Message-ID: <541A0C4A.3020906@redhat.com> (raw)
In-Reply-To: <1410989576-9311-2-git-send-email-mdroth@linux.vnet.ibm.com>
[-- Attachment #1: Type: text/plain, Size: 2117 bytes --]
On 09/17/2014 03:32 PM, Michael Roth wrote:
> In some cases an input visitor might bail out on filling out a
> struct for various reasons, such as missing fields when running
> in strict mode. In the case of a QAPI Union type, this may lead
> to cases where the .kind field which encodes the union type
> is uninitialized. Subsequently, other visitors, such as the
> dealloc visitor, may use this .kind value as if it were
> initialized, leading to assumptions about the union type which
> in this case may lead to segfaults. For example, freeing an
> integer value.
>
> However, we can generally rely on the fact that the always-present
> .data void * field that we generate for these union types will
> always be NULL in cases where .kind is uninitialized (at least,
> there shouldn't be a reason where we'd do this purposefully).
>
> So pass this information on to Visitor implementation via these
> optional start_union/end_union interfaces so this information
> can be used to guard against the situation above. We will make
> use of this information in a subsequent patch for the dealloc
> visitor.
>
> Cc: qemu-stable@nongnu.org
> Reported-by: Fam Zheng <famz@redhat.com>
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
> ---
Reviewed-by: Eric Blake <eblake@redhat.com>
>
> +bool visit_start_union(Visitor *v, bool data_present, Error **errp)
> +{
> + if (v->start_union) {
> + return v->start_union(v, data_present, errp);
> + }
> + return true;
> +}
So we default to returning true (which implies safe to visit the union
fields), and patch 2 creates the only case where this returns false
(when data_present is false). I also note that errp is never set by
this series, but it's fine to wire it up in anticipation of any future
need. Took me a couple reads to get what's happening, but I agree with
the results.
--
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: 539 bytes --]
next prev parent reply other threads:[~2014-09-17 23:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-17 21:32 [Qemu-devel] [PATCH v2 0/4] qapi: fix crash in dealloc visitor for union types Michael Roth
2014-09-17 21:32 ` [Qemu-devel] [PATCH v2 1/4] qapi: add visit_start_union and visit_end_union Michael Roth
2014-09-17 22:33 ` Eric Blake [this message]
2014-09-17 21:32 ` [Qemu-devel] [PATCH v2 2/4] qapi: dealloc visitor, implement visit_start_union Michael Roth
2014-09-17 22:27 ` Eric Blake
2014-09-17 21:32 ` [Qemu-devel] [PATCH v2 3/4] tests: add QMP input visitor test for unions with no discriminator Michael Roth
2014-09-17 22:33 ` Eric Blake
2014-09-18 20:19 ` Michael Roth
2014-09-17 21:32 ` [Qemu-devel] [PATCH v2 4/4] qemu-iotests: Test missing "driver" key for blockdev-add Michael Roth
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=541A0C4A.3020906@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=famz@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@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).