mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 20:33:54 -06:00
qapi.py: Fix schema parser to check syntax systematically
Fixes at least the following parser bugs: * accepts any token in place of a colon * treats comma as optional * crashes when closing braces or brackets are missing Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 1374939721-7876-7-git-send-email-armbru@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
9213aa5391
commit
6974ccd542
18 changed files with 42 additions and 32 deletions
|
@ -106,24 +106,42 @@ class QAPISchema:
|
|||
|
||||
def get_members(self):
|
||||
expr = OrderedDict()
|
||||
while self.tok != '}':
|
||||
if self.tok == '}':
|
||||
self.accept()
|
||||
return expr
|
||||
if self.tok != "'":
|
||||
raise QAPISchemaError(self, 'Expected string or "}"')
|
||||
while True:
|
||||
key = self.val
|
||||
self.accept()
|
||||
self.accept() # :
|
||||
if self.tok != ':':
|
||||
raise QAPISchemaError(self, 'Expected ":"')
|
||||
self.accept()
|
||||
expr[key] = self.get_expr()
|
||||
if self.tok == ',':
|
||||
if self.tok == '}':
|
||||
self.accept()
|
||||
self.accept()
|
||||
return expr
|
||||
return expr
|
||||
if self.tok != ',':
|
||||
raise QAPISchemaError(self, 'Expected "," or "}"')
|
||||
self.accept()
|
||||
if self.tok != "'":
|
||||
raise QAPISchemaError(self, 'Expected string')
|
||||
|
||||
def get_values(self):
|
||||
expr = []
|
||||
while self.tok != ']':
|
||||
if self.tok == ']':
|
||||
self.accept()
|
||||
return expr
|
||||
if not self.tok in [ '{', '[', "'" ]:
|
||||
raise QAPISchemaError(self, 'Expected "{", "[", "]" or string')
|
||||
while True:
|
||||
expr.append(self.get_expr())
|
||||
if self.tok == ',':
|
||||
if self.tok == ']':
|
||||
self.accept()
|
||||
self.accept()
|
||||
return expr
|
||||
return expr
|
||||
if self.tok != ',':
|
||||
raise QAPISchemaError(self, 'Expected "," or "]"')
|
||||
self.accept()
|
||||
|
||||
def get_expr(self):
|
||||
if self.tok == '{':
|
||||
|
@ -132,9 +150,11 @@ class QAPISchema:
|
|||
elif self.tok == '[':
|
||||
self.accept()
|
||||
expr = self.get_values()
|
||||
else:
|
||||
elif self.tok == "'":
|
||||
expr = self.val
|
||||
self.accept()
|
||||
else:
|
||||
raise QAPISchemaError(self, 'Expected "{", "[" or string')
|
||||
return expr
|
||||
|
||||
def parse_schema(fp):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue