From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37688) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYFcn-0006rQ-36 for qemu-devel@nongnu.org; Thu, 20 Jul 2017 13:52:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYFck-0005ha-18 for qemu-devel@nongnu.org; Thu, 20 Jul 2017 13:52:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42830) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYFcj-0005hV-Qo for qemu-devel@nongnu.org; Thu, 20 Jul 2017 13:52:29 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B695467AFE for ; Thu, 20 Jul 2017 17:52:28 +0000 (UTC) Date: Thu, 20 Jul 2017 14:52:23 -0300 From: Eduardo Habkost Message-ID: <20170720175223.GR2757@localhost.localdomain> References: <20170717180926.14924-1-ehabkost@redhat.com> <877ez3rsp7.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <877ez3rsp7.fsf@dusky.pond.sub.org> Subject: Re: [Qemu-devel] [PATCH v2] qapi: Fix error handling code on alternate conflict List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: qemu-devel@nongnu.org, =?iso-8859-1?Q?Marc-Andr=E9?= Lureau On Thu, Jul 20, 2017 at 06:14:44PM +0200, Markus Armbruster wrote: > Eduardo Habkost writes: > > > The conflict check added by commit c0644771 ("qapi: Reject > > alternates that can't work with keyval_parse()") doesn't work > > with the following declaration: > > > > { 'alternate': 'Alt', > > 'data': { 'one': 'bool', > > 'two': 'str' } } > > > > It crashes with: > > > > Traceback (most recent call last): > > File "./scripts/qapi-types.py", line 295, in > > schema = QAPISchema(input_file) > > File "/home/ehabkost/rh/proj/virt/qemu/scripts/qapi.py", line 1468, in __init__ > > self.exprs = check_exprs(parser.exprs) > > File "/home/ehabkost/rh/proj/virt/qemu/scripts/qapi.py", line 958, in check_exprs > > check_alternate(expr, info) > > File "/home/ehabkost/rh/proj/virt/qemu/scripts/qapi.py", line 830, in check_alternate > > % (name, key, types_seen[qtype])) > > KeyError: 'QTYPE_QSTRING' > > > > This happens because the previously-seen conflicting member > > ('one') can't be found at types_seen[qtype], but at > > types_seen['QTYPE_BOOL']. > > > > Fix the bug by moving the error check to the same loop that adds > > new items to types_seen, raising an exception if types_seen[qt] > > is already set. > > > > Add two additional test cases that can detect the bug. > > > > Signed-off-by: Eduardo Habkost > [...] > > diff --git a/tests/qapi-schema/alternate-conflict-num-string.out b/tests/qapi-schema/alternate-conflict-num-string.out > > new file mode 100644 > > index 0000000..e69de29 > > diff --git a/tests/qapi-schema/alternate-multi-conflict.json b/tests/qapi-schema/alternate-multi-conflict.json > > new file mode 100644 > > index 0000000..e69de29 > > Accident? Can drop on commit. Yes, sorry. Thanks for spotting it. -- Eduardo