From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44947) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUOWn-0006FO-1s for qemu-devel@nongnu.org; Wed, 17 Sep 2014 19:20:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XUOWf-0004tD-V7 for qemu-devel@nongnu.org; Wed, 17 Sep 2014 19:20:49 -0400 Received: from resqmta-po-12v.sys.comcast.net ([96.114.154.171]:60858) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUOWf-0004sl-Qz for qemu-devel@nongnu.org; Wed, 17 Sep 2014 19:20:41 -0400 Message-ID: <541A0C4A.3020906@redhat.com> Date: Wed, 17 Sep 2014 16:33:46 -0600 From: Eric Blake MIME-Version: 1.0 References: <1410989576-9311-1-git-send-email-mdroth@linux.vnet.ibm.com> <1410989576-9311-2-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1410989576-9311-2-git-send-email-mdroth@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="gEkVTC5DdDknu5qDUlg5ap9Ea2ESbf5Ca" Subject: Re: [Qemu-devel] [PATCH v2 1/4] qapi: add visit_start_union and visit_end_union List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Roth , qemu-devel@nongnu.org Cc: pbonzini@redhat.com, lcapitulino@redhat.com, famz@redhat.com, qemu-stable@nongnu.org, armbru@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --gEkVTC5DdDknu5qDUlg5ap9Ea2ESbf5Ca Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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. >=20 > 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). >=20 > 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. >=20 > Cc: qemu-stable@nongnu.org > Reported-by: Fam Zheng > Suggested-by: Paolo Bonzini > Reviewed-by: Paolo Bonzini > Signed-off-by: Michael Roth > --- Reviewed-by: Eric Blake > =20 > +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. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --gEkVTC5DdDknu5qDUlg5ap9Ea2ESbf5Ca Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg iQEcBAEBCAAGBQJUGgxKAAoJEKeha0olJ0NqOGgIAIaWjbEvYlr45caLISg0hJ2X DLLSZ+/DCQF0hXaWDF9CnQQ77THG2gpPJBgSfRwwcM9s9QRvRZQhGWqR8rowM4du zV4ONKzXh4ci8E/KbuEfN7W4UXeruXavD3rbIr2Hv44Pxw2S22tnpWlewF0hjPDJ k/0DgydiRz/uSHy6qebgAOxI4nD8yrKIos8TKxhdWT2NTAPLcSzQKyZopEHfKpdL JnDWz33cG2tGvqcImntgqGoMQz8gHvam5u2vF/eAIhc/CGNoieNOcLho64xDStW6 oN+HfcxRbLRbfLnvcORZnQhrnYzplj7W1eXMlO84nXvjx/cWnHm2hWskhNIV9Ik= =rVfv -----END PGP SIGNATURE----- --gEkVTC5DdDknu5qDUlg5ap9Ea2ESbf5Ca--