mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 04:13:53 -06:00
qapi/expr.py: Check type of union and alternate 'data' member
Prior to this commit, specifying a non-object value here causes the QAPI parser to crash in expr.py with a stack trace with (likely) an AttributeError when we attempt to call that value's items() method. This member needs to be an object (Dict), and not anything else. Add a check for this with a nicer error message, and formalize that check with new test cases that exercise that error. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210421182032.3521476-8-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
926bb8add7
commit
4918bb7def
8 changed files with 23 additions and 0 deletions
|
@ -283,6 +283,9 @@ def check_union(expr, info):
|
|||
raise QAPISemError(info, "'discriminator' requires 'base'")
|
||||
check_name_is_str(discriminator, info, "'discriminator'")
|
||||
|
||||
if not isinstance(members, dict):
|
||||
raise QAPISemError(info, "'data' must be an object")
|
||||
|
||||
for (key, value) in members.items():
|
||||
source = "'data' member '%s'" % key
|
||||
if discriminator is None:
|
||||
|
@ -298,6 +301,10 @@ def check_alternate(expr, info):
|
|||
|
||||
if not members:
|
||||
raise QAPISemError(info, "'data' must not be empty")
|
||||
|
||||
if not isinstance(members, dict):
|
||||
raise QAPISemError(info, "'data' must be an object")
|
||||
|
||||
for (key, value) in members.items():
|
||||
source = "'data' member '%s'" % key
|
||||
check_name_lower(key, info, source)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue