diff options
author | Markus Armbruster <armbru@redhat.com> | 2021-06-16 09:21:21 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2021-07-15 12:56:41 +0200 |
commit | a0c7b99bf75d85b616fa219a7d866fc72970f327 (patch) | |
tree | a43425f05892b181fe6068474b5bbc4868ffcf22 | |
parent | a9649a719a44894b81f38dc1c5c1888ee684acef (diff) | |
download | qemu-a0c7b99bf75d85b616fa219a7d866fc72970f327.zip qemu-a0c7b99bf75d85b616fa219a7d866fc72970f327.tar.gz qemu-a0c7b99bf75d85b616fa219a7d866fc72970f327.tar.bz2 |
qapi: Fix crash on missing enum member name
New test case enum-dict-no-name.json crashes:
$ python3 scripts/qapi-gen.py tests/qapi-schema/enum-dict-no-name.json
Traceback (most recent call last):
[...]
File "/work/armbru/qemu/scripts/qapi/expr.py", line 458, in check_enum
member_name = member['name']
KeyError: 'name'
Root cause: we try to retrieve member 'name' before we check for
missing members. With that fixed, we get the expected error "'data'
member misses key 'name'".
Fixes: 0825f62c842f2c07c5471391c6d7fd3f4fe83732
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20210616072121.626431-1-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
-rw-r--r-- | scripts/qapi/expr.py | 2 | ||||
-rw-r--r-- | tests/qapi-schema/enum-dict-no-name.err | 2 | ||||
-rw-r--r-- | tests/qapi-schema/enum-dict-no-name.json | 2 | ||||
-rw-r--r-- | tests/qapi-schema/enum-dict-no-name.out | 0 |
4 files changed, 5 insertions, 1 deletions
diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 496f7e0..cf98923 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -455,8 +455,8 @@ def check_enum(expr: _JSONObject, info: QAPISourceInfo) -> None: for m in members] for member in members: source = "'data' member" - member_name = member['name'] check_keys(member, info, source, ['name'], ['if']) + member_name = member['name'] check_name_is_str(member_name, info, source) source = "%s '%s'" % (source, member_name) # Enum members may start with a digit diff --git a/tests/qapi-schema/enum-dict-no-name.err b/tests/qapi-schema/enum-dict-no-name.err new file mode 100644 index 0000000..3ce0c16 --- /dev/null +++ b/tests/qapi-schema/enum-dict-no-name.err @@ -0,0 +1,2 @@ +enum-dict-no-name.json: In enum 'Enum': +enum-dict-no-name.json:2: 'data' member misses key 'name' diff --git a/tests/qapi-schema/enum-dict-no-name.json b/tests/qapi-schema/enum-dict-no-name.json new file mode 100644 index 0000000..5952a86 --- /dev/null +++ b/tests/qapi-schema/enum-dict-no-name.json @@ -0,0 +1,2 @@ +# enum member lacking a name +{ 'enum': 'Enum', 'data': [ {} ] } diff --git a/tests/qapi-schema/enum-dict-no-name.out b/tests/qapi-schema/enum-dict-no-name.out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/qapi-schema/enum-dict-no-name.out |