[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] qapi: Fix error handling code on alternate conf
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH] qapi: Fix error handling code on alternate conflict |
Date: |
Mon, 17 Jul 2017 09:45:01 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 |
On 07/14/2017 03:33 PM, Eduardo Habkost wrote:
> 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 <module>
> 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 <address@hidden>
> ---
> +++ b/tests/qapi-schema/alternate-conflict-bool-string.err
> @@ -0,0 +1 @@
> +tests/qapi-schema/alternate-conflict-bool-string.json:3: Alternate 'Alt'
> member 'two' can't be distinguished from member 'one'
Claims the error is at line 3,
> +++ 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',
but the declaration starts at line 2. That's probably why patchew
complained that your patch doesn't build. The idea looks sane, though;
looking forward to v2.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature