From nobody Tue Nov 4 13:08:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504270704178853.8003558816843; Fri, 1 Sep 2017 05:58:24 -0700 (PDT) Received: from localhost ([::1]:39885 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnlWh-0001yB-44 for importer@patchew.org; Fri, 01 Sep 2017 08:58:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53821) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnlUi-0000F1-1W for qemu-devel@nongnu.org; Fri, 01 Sep 2017 08:56:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnlUd-0007IH-9X for qemu-devel@nongnu.org; Fri, 01 Sep 2017 08:56:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34520) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnlUd-0007Hr-0Q for qemu-devel@nongnu.org; Fri, 01 Sep 2017 08:56:15 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 01E147F3F9 for ; Fri, 1 Sep 2017 12:56:14 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9DFBA7B0E3; Fri, 1 Sep 2017 12:56:13 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 020AA1138663; Fri, 1 Sep 2017 14:56:11 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 01E147F3F9 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=armbru@redhat.com From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 1 Sep 2017 14:55:25 +0200 Message-Id: <20170901125611.29295-2-armbru@redhat.com> In-Reply-To: <20170901125611.29295-1-armbru@redhat.com> References: <20170901125611.29295-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 01 Sep 2017 12:56:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 01/47] qapi: Fix error handling code on alternate conflict X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Eduardo Habkost 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 =3D QAPISchema(input_file) File "/home/ehabkost/rh/proj/virt/qemu/scripts/qapi.py", line 1468, in = __init__ self.exprs =3D check_exprs(parser.exprs) File "/home/ehabkost/rh/proj/virt/qemu/scripts/qapi.py", line 958, in c= heck_exprs check_alternate(expr, info) File "/home/ehabkost/rh/proj/virt/qemu/scripts/qapi.py", line 830, in c= heck_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 Message-Id: <20170717180926.14924-1-ehabkost@redhat.com> Signed-off-by: Markus Armbruster --- scripts/qapi.py | 8 ++++---- tests/Makefile.include | 2 ++ tests/qapi-schema/alternate-conflict-bool-string.err | 1 + tests/qapi-schema/alternate-conflict-bool-string.exit | 1 + tests/qapi-schema/alternate-conflict-bool-string.json | 4 ++++ tests/qapi-schema/alternate-conflict-bool-string.out | 0 tests/qapi-schema/alternate-conflict-num-string.err | 1 + tests/qapi-schema/alternate-conflict-num-string.exit | 1 + tests/qapi-schema/alternate-conflict-num-string.json | 4 ++++ tests/qapi-schema/alternate-conflict-num-string.out | 0 10 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 tests/qapi-schema/alternate-conflict-bool-string.err create mode 100644 tests/qapi-schema/alternate-conflict-bool-string.exit create mode 100644 tests/qapi-schema/alternate-conflict-bool-string.json create mode 100644 tests/qapi-schema/alternate-conflict-bool-string.out create mode 100644 tests/qapi-schema/alternate-conflict-num-string.err create mode 100644 tests/qapi-schema/alternate-conflict-num-string.exit create mode 100644 tests/qapi-schema/alternate-conflict-num-string.json create mode 100644 tests/qapi-schema/alternate-conflict-num-string.out diff --git a/scripts/qapi.py b/scripts/qapi.py index 8aa2775f12..3693b520da 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -825,11 +825,11 @@ def check_alternate(expr, info): else: conflicting.add('QTYPE_QNUM') conflicting.add('QTYPE_QBOOL') - if conflicting & set(types_seen): - raise QAPISemError(info, "Alternate '%s' member '%s' can't " - "be distinguished from member '%s'" - % (name, key, types_seen[qtype])) for qt in conflicting: + if qt in types_seen: + raise QAPISemError(info, "Alternate '%s' member '%s' can't= " + "be distinguished from member '%s'" + % (name, key, types_seen[qt])) types_seen[qt] =3D key =20 =20 diff --git a/tests/Makefile.include b/tests/Makefile.include index f08b7418f0..00af45ca85 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -376,6 +376,8 @@ qapi-schema +=3D alternate-conflict-dict.json qapi-schema +=3D alternate-conflict-enum-bool.json qapi-schema +=3D alternate-conflict-enum-int.json qapi-schema +=3D alternate-conflict-string.json +qapi-schema +=3D alternate-conflict-bool-string.json +qapi-schema +=3D alternate-conflict-num-string.json qapi-schema +=3D alternate-empty.json qapi-schema +=3D alternate-nested.json qapi-schema +=3D alternate-unknown.json diff --git a/tests/qapi-schema/alternate-conflict-bool-string.err b/tests/q= api-schema/alternate-conflict-bool-string.err new file mode 100644 index 0000000000..e52fee7620 --- /dev/null +++ b/tests/qapi-schema/alternate-conflict-bool-string.err @@ -0,0 +1 @@ +tests/qapi-schema/alternate-conflict-bool-string.json:2: Alternate 'Alt' m= ember 'two' can't be distinguished from member 'one' diff --git a/tests/qapi-schema/alternate-conflict-bool-string.exit b/tests/= qapi-schema/alternate-conflict-bool-string.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/alternate-conflict-bool-string.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/alternate-conflict-bool-string.json b/tests/= qapi-schema/alternate-conflict-bool-string.json new file mode 100644 index 0000000000..0544de10f3 --- /dev/null +++ b/tests/qapi-schema/alternate-conflict-bool-string.json @@ -0,0 +1,4 @@ +# alternate branches of 'str' type conflict with all scalar types +{ 'alternate': 'Alt', + 'data': { 'one': 'bool', + 'two': 'str' } } diff --git a/tests/qapi-schema/alternate-conflict-bool-string.out b/tests/q= api-schema/alternate-conflict-bool-string.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/alternate-conflict-num-string.err b/tests/qa= pi-schema/alternate-conflict-num-string.err new file mode 100644 index 0000000000..5ba3827dd1 --- /dev/null +++ b/tests/qapi-schema/alternate-conflict-num-string.err @@ -0,0 +1 @@ +tests/qapi-schema/alternate-conflict-num-string.json:2: Alternate 'Alt' me= mber 'two' can't be distinguished from member 'one' diff --git a/tests/qapi-schema/alternate-conflict-num-string.exit b/tests/q= api-schema/alternate-conflict-num-string.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/alternate-conflict-num-string.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/alternate-conflict-num-string.json b/tests/q= api-schema/alternate-conflict-num-string.json new file mode 100644 index 0000000000..ae901449af --- /dev/null +++ b/tests/qapi-schema/alternate-conflict-num-string.json @@ -0,0 +1,4 @@ +# alternate branches of 'str' type conflict with all scalar types +{ 'alternate': 'Alt', + 'data': { 'one': 'number', + 'two': 'str' } } diff --git a/tests/qapi-schema/alternate-conflict-num-string.out b/tests/qa= pi-schema/alternate-conflict-num-string.out new file mode 100644 index 0000000000..e69de29bb2 --=20 2.13.5