Received: from eggs.gnu.org ([2001:4830:134:3::10]:51427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRw9B-0005jZ-QH for qemu-devel@nongnu.org; Thu, 11 Sep 2014 00:38:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XRw96-0004D4-Rs for qemu-devel@nongnu.org; Thu, 11 Sep 2014 00:38:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52812) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRw96-0004Cf-Ky for qemu-devel@nongnu.org; Thu, 11 Sep 2014 00:38:12 -0400 Date: Thu, 11 Sep 2014 12:38:03 +0800 From: Fam Zheng Message-ID: <20140911043803.GA28795@fam-t430.nay.redhat.com> References: <1410352239-8705-1-git-send-email-famz@redhat.com> <54104BA9.4040308@redhat.com> <20140910150200.GA4883@fam-t430.nay.redhat.com> <54106F28.5080203@redhat.com> <20140911005328.GB2554@fam-t430.nay.redhat.com> <54112247.40303@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <54112247.40303@redhat.com> Subject: Re: [Qemu-devel] [PATCH] qapi: Fix crash with enum dealloc when kind is invalid List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Kevin Wolf , Markus Armbruster , Michael Roth , qemu-devel@nongnu.org, Stefan Hajnoczi , Hu Tao , Paolo Bonzini , Luiz Capitulino On Wed, 09/10 22:17, Eric Blake wrote: > On 09/10/2014 06:53 PM, Fam Zheng wrote: > > On Wed, 09/10 17:32, Paolo Bonzini wrote: > >> Il 10/09/2014 17:02, Fam Zheng ha scritto: > >>>> A bit hackish, but I don't have any better idea. > >>>> > >>>> Hmm... what about adding a new member to the visitors for "invalid enum" > >>>> value? The dealloc visitor could override it to do nothing, while the > >>>> default could abort or set an error. Would that work? > >>> > >>> The invalid state of enum still needs to be saved in the data. It is detected > >>> by the input visitor, but should be checked by other visitors (output, dealloc) > >>> later. > >> > >> Yes, that's fine. The only part where I'm not sure is the special > >> casing of the _MAX enum. > >> > > > > Yes, it is abusing. Let's add an _INVALID = 0 enum which is much clearer. > > If I understand correctly, you mean that for: > > { 'enum': 'Foo', 'data': [ 'one', 'two' ] } > > FOO_ONE would now be 1 instead of its current value of 0? > > We just barely saw a case where Hu Tao's code was relying on the > implicit value 0 assigned to the first enum in the json file [1] > although I strongly argued that it should be nuked (and so it was fixed > in [2]). So I could live with reserving 0 for internal use for flagging > parse errors (such as attempting to pass the string 'three' where a Foo > value is expected). > > [1] https://lists.gnu.org/archive/html/qemu-devel/2014-09/msg01691.html > [2] https://lists.gnu.org/archive/html/qemu-devel/2014-09/msg01938.html > A closer looking shows me a huge risk with _lookup table. We have for loops starting with index 0 all over the place to peek info _lookup arrays, but in this case it is _INVALID and shouldn't be looked at. Maybe we have to put _INVALID at the end after _MAX. Fam