]> www.infradead.org Git - users/dwmw2/qemu.git/commit
qapi: Fix error handling code on alternate conflict
authorEduardo Habkost <ehabkost@redhat.com>
Mon, 17 Jul 2017 18:09:26 +0000 (15:09 -0300)
committerMarkus Armbruster <armbru@redhat.com>
Fri, 1 Sep 2017 10:51:04 +0000 (12:51 +0200)
commitfda72ab4510bcc680a3c4fe55997aa29589884f7
tree40cf0dcb520d573ee06aa48fb4ae314bd378cd5f
parent223cd0e13f2e46078d7b573f0b8402bfbee339be
qapi: Fix error handling code on alternate conflict

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 <ehabkost@redhat.com>
Message-Id: <20170717180926.14924-1-ehabkost@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
scripts/qapi.py
tests/Makefile.include
tests/qapi-schema/alternate-conflict-bool-string.err [new file with mode: 0644]
tests/qapi-schema/alternate-conflict-bool-string.exit [new file with mode: 0644]
tests/qapi-schema/alternate-conflict-bool-string.json [new file with mode: 0644]
tests/qapi-schema/alternate-conflict-bool-string.out [new file with mode: 0644]
tests/qapi-schema/alternate-conflict-num-string.err [new file with mode: 0644]
tests/qapi-schema/alternate-conflict-num-string.exit [new file with mode: 0644]
tests/qapi-schema/alternate-conflict-num-string.json [new file with mode: 0644]
tests/qapi-schema/alternate-conflict-num-string.out [new file with mode: 0644]