From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38432) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zmbxg-0004ru-NG for qemu-devel@nongnu.org; Thu, 15 Oct 2015 02:24:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zmbxd-0005lG-Jv for qemu-devel@nongnu.org; Thu, 15 Oct 2015 02:24:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55929) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zmbxd-0005l2-F1 for qemu-devel@nongnu.org; Thu, 15 Oct 2015 02:24:21 -0400 From: Markus Armbruster References: <1444861825-19256-1-git-send-email-eblake@redhat.com> Date: Thu, 15 Oct 2015 08:24:17 +0200 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") Message-ID: <87wpuoodim.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2] qapi: Fix regression with '-netdev ?' List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: marcandre.lureau@gmail.com, qemu-devel@nongnu.org, Michael Roth Eric Blake 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=C3=A9 Lureau > Signed-off-by: Eric Blake > --- > 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 **o= bj, const char *name, Error > out_obj: > error_propagate(errp, err); > err =3D NULL; > - visit_end_union(v, !!(*obj)->data, &err); > + if (*obj) { > + visit_end_union(v, !!(*obj)->data, &err); > + } > error_propagate(errp, err); > err =3D 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_na= me)s), &err); if (err) { goto out; } if (*obj) { [...] out_obj: error_propagate(errp, err); err =3D NULL; visit_end_union(v, !!(*obj)->data, &err); error_propagate(errp, err); err =3D NULL; } visit_end_struct(v, &err); out: Since then visit_start_struct(v, (void **)obj, "%(name)s", name, sizeof(%(c_na= me)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 =3D NULL; // This code beca= me visit_end_union(v, !!(*obj)->data, &err); // accidentally error_propagate(errp, err); // unconditional err =3D 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!