|
|
9ae3a8 |
From d7e41b169b7c97953ceda7b7e617ae3f3dc5ae49 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
Message-Id: <d7e41b169b7c97953ceda7b7e617ae3f3dc5ae49.1387369730.git.minovotn@redhat.com>
|
|
|
9ae3a8 |
In-Reply-To: <091eecc4fa42754760dfff393dabcc2b444e9693.1387369730.git.minovotn@redhat.com>
|
|
|
9ae3a8 |
References: <091eecc4fa42754760dfff393dabcc2b444e9693.1387369730.git.minovotn@redhat.com>
|
|
|
9ae3a8 |
From: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
Date: Tue, 10 Dec 2013 15:29:16 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 16/21] qapi.py: Fix schema parser to check syntax
|
|
|
9ae3a8 |
systematically
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1386689361-30281-14-git-send-email-armbru@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 56134
|
|
|
9ae3a8 |
O-Subject: [PATCH 7.0 qemu-kvm 13/18] qapi.py: Fix schema parser to check syntax systematically
|
|
|
9ae3a8 |
Bugzilla: 997915
|
|
|
9ae3a8 |
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
From: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Fixes at least the following parser bugs:
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
* accepts any token in place of a colon
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
* treats comma as optional
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
* crashes when closing braces or brackets are missing
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
9ae3a8 |
Message-id: 1374939721-7876-7-git-send-email-armbru@redhat.com
|
|
|
9ae3a8 |
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
|
|
|
9ae3a8 |
(cherry picked from commit 6974ccd542d11ae5fb1e56dd3d753f2de5cc097e)
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
scripts/qapi.py | 40 +++++++++++++++++++++-------
|
|
|
9ae3a8 |
tests/qapi-schema/missing-colon.err | 1 +
|
|
|
9ae3a8 |
tests/qapi-schema/missing-colon.exit | 2 +-
|
|
|
9ae3a8 |
tests/qapi-schema/missing-colon.out | 3 ---
|
|
|
9ae3a8 |
tests/qapi-schema/missing-comma-list.err | 1 +
|
|
|
9ae3a8 |
tests/qapi-schema/missing-comma-list.exit | 2 +-
|
|
|
9ae3a8 |
tests/qapi-schema/missing-comma-list.out | 3 ---
|
|
|
9ae3a8 |
tests/qapi-schema/missing-comma-object.err | 1 +
|
|
|
9ae3a8 |
tests/qapi-schema/missing-comma-object.exit | 2 +-
|
|
|
9ae3a8 |
tests/qapi-schema/missing-comma-object.out | 3 ---
|
|
|
9ae3a8 |
tests/qapi-schema/trailing-comma-list.err | 1 +
|
|
|
9ae3a8 |
tests/qapi-schema/trailing-comma-list.exit | 2 +-
|
|
|
9ae3a8 |
tests/qapi-schema/trailing-comma-list.out | 3 ---
|
|
|
9ae3a8 |
tests/qapi-schema/trailing-comma-object.err | 1 +
|
|
|
9ae3a8 |
tests/qapi-schema/trailing-comma-object.exit | 2 +-
|
|
|
9ae3a8 |
tests/qapi-schema/trailing-comma-object.out | 3 ---
|
|
|
9ae3a8 |
tests/qapi-schema/unclosed-list.err | 2 +-
|
|
|
9ae3a8 |
tests/qapi-schema/unclosed-object.err | 2 +-
|
|
|
9ae3a8 |
18 files changed, 42 insertions(+), 32 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Michal Novotny <minovotn@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
scripts/qapi.py | 40 +++++++++++++++++++++-------
|
|
|
9ae3a8 |
tests/qapi-schema/missing-colon.err | 1 +
|
|
|
9ae3a8 |
tests/qapi-schema/missing-colon.exit | 2 +-
|
|
|
9ae3a8 |
tests/qapi-schema/missing-colon.out | 3 ---
|
|
|
9ae3a8 |
tests/qapi-schema/missing-comma-list.err | 1 +
|
|
|
9ae3a8 |
tests/qapi-schema/missing-comma-list.exit | 2 +-
|
|
|
9ae3a8 |
tests/qapi-schema/missing-comma-list.out | 3 ---
|
|
|
9ae3a8 |
tests/qapi-schema/missing-comma-object.err | 1 +
|
|
|
9ae3a8 |
tests/qapi-schema/missing-comma-object.exit | 2 +-
|
|
|
9ae3a8 |
tests/qapi-schema/missing-comma-object.out | 3 ---
|
|
|
9ae3a8 |
tests/qapi-schema/trailing-comma-list.err | 1 +
|
|
|
9ae3a8 |
tests/qapi-schema/trailing-comma-list.exit | 2 +-
|
|
|
9ae3a8 |
tests/qapi-schema/trailing-comma-list.out | 3 ---
|
|
|
9ae3a8 |
tests/qapi-schema/trailing-comma-object.err | 1 +
|
|
|
9ae3a8 |
tests/qapi-schema/trailing-comma-object.exit | 2 +-
|
|
|
9ae3a8 |
tests/qapi-schema/trailing-comma-object.out | 3 ---
|
|
|
9ae3a8 |
tests/qapi-schema/unclosed-list.err | 2 +-
|
|
|
9ae3a8 |
tests/qapi-schema/unclosed-object.err | 2 +-
|
|
|
9ae3a8 |
18 files changed, 42 insertions(+), 32 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/scripts/qapi.py b/scripts/qapi.py
|
|
|
9ae3a8 |
index 0b48a1e..12fb29a 100644
|
|
|
9ae3a8 |
--- a/scripts/qapi.py
|
|
|
9ae3a8 |
+++ b/scripts/qapi.py
|
|
|
9ae3a8 |
@@ -106,24 +106,42 @@ class QAPISchema:
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
def get_members(self):
|
|
|
9ae3a8 |
expr = OrderedDict()
|
|
|
9ae3a8 |
- while self.tok != '}':
|
|
|
9ae3a8 |
+ if self.tok == '}':
|
|
|
9ae3a8 |
+ self.accept()
|
|
|
9ae3a8 |
+ return expr
|
|
|
9ae3a8 |
+ if self.tok != "'":
|
|
|
9ae3a8 |
+ raise QAPISchemaError(self, 'Expected string or "}"')
|
|
|
9ae3a8 |
+ while True:
|
|
|
9ae3a8 |
key = self.val
|
|
|
9ae3a8 |
self.accept()
|
|
|
9ae3a8 |
- self.accept() # :
|
|
|
9ae3a8 |
+ if self.tok != ':':
|
|
|
9ae3a8 |
+ raise QAPISchemaError(self, 'Expected ":"')
|
|
|
9ae3a8 |
+ self.accept()
|
|
|
9ae3a8 |
expr[key] = self.get_expr()
|
|
|
9ae3a8 |
- if self.tok == ',':
|
|
|
9ae3a8 |
+ if self.tok == '}':
|
|
|
9ae3a8 |
self.accept()
|
|
|
9ae3a8 |
- self.accept()
|
|
|
9ae3a8 |
- return expr
|
|
|
9ae3a8 |
+ return expr
|
|
|
9ae3a8 |
+ if self.tok != ',':
|
|
|
9ae3a8 |
+ raise QAPISchemaError(self, 'Expected "," or "}"')
|
|
|
9ae3a8 |
+ self.accept()
|
|
|
9ae3a8 |
+ if self.tok != "'":
|
|
|
9ae3a8 |
+ raise QAPISchemaError(self, 'Expected string')
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
def get_values(self):
|
|
|
9ae3a8 |
expr = []
|
|
|
9ae3a8 |
- while self.tok != ']':
|
|
|
9ae3a8 |
+ if self.tok == ']':
|
|
|
9ae3a8 |
+ self.accept()
|
|
|
9ae3a8 |
+ return expr
|
|
|
9ae3a8 |
+ if not self.tok in [ '{', '[', "'" ]:
|
|
|
9ae3a8 |
+ raise QAPISchemaError(self, 'Expected "{", "[", "]" or string')
|
|
|
9ae3a8 |
+ while True:
|
|
|
9ae3a8 |
expr.append(self.get_expr())
|
|
|
9ae3a8 |
- if self.tok == ',':
|
|
|
9ae3a8 |
+ if self.tok == ']':
|
|
|
9ae3a8 |
self.accept()
|
|
|
9ae3a8 |
- self.accept()
|
|
|
9ae3a8 |
- return expr
|
|
|
9ae3a8 |
+ return expr
|
|
|
9ae3a8 |
+ if self.tok != ',':
|
|
|
9ae3a8 |
+ raise QAPISchemaError(self, 'Expected "," or "]"')
|
|
|
9ae3a8 |
+ self.accept()
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
def get_expr(self):
|
|
|
9ae3a8 |
if self.tok == '{':
|
|
|
9ae3a8 |
@@ -132,9 +150,11 @@ class QAPISchema:
|
|
|
9ae3a8 |
elif self.tok == '[':
|
|
|
9ae3a8 |
self.accept()
|
|
|
9ae3a8 |
expr = self.get_values()
|
|
|
9ae3a8 |
- else:
|
|
|
9ae3a8 |
+ elif self.tok == "'":
|
|
|
9ae3a8 |
expr = self.val
|
|
|
9ae3a8 |
self.accept()
|
|
|
9ae3a8 |
+ else:
|
|
|
9ae3a8 |
+ raise QAPISchemaError(self, 'Expected "{", "[" or string')
|
|
|
9ae3a8 |
return expr
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
def parse_schema(fp):
|
|
|
9ae3a8 |
diff --git a/tests/qapi-schema/missing-colon.err b/tests/qapi-schema/missing-colon.err
|
|
|
9ae3a8 |
index e69de29..9f2a355 100644
|
|
|
9ae3a8 |
--- a/tests/qapi-schema/missing-colon.err
|
|
|
9ae3a8 |
+++ b/tests/qapi-schema/missing-colon.err
|
|
|
9ae3a8 |
@@ -0,0 +1 @@
|
|
|
9ae3a8 |
+<stdin>:1:10: Expected ":"
|
|
|
9ae3a8 |
diff --git a/tests/qapi-schema/missing-colon.exit b/tests/qapi-schema/missing-colon.exit
|
|
|
9ae3a8 |
index 573541a..d00491f 100644
|
|
|
9ae3a8 |
--- a/tests/qapi-schema/missing-colon.exit
|
|
|
9ae3a8 |
+++ b/tests/qapi-schema/missing-colon.exit
|
|
|
9ae3a8 |
@@ -1 +1 @@
|
|
|
9ae3a8 |
-0
|
|
|
9ae3a8 |
+1
|
|
|
9ae3a8 |
diff --git a/tests/qapi-schema/missing-colon.out b/tests/qapi-schema/missing-colon.out
|
|
|
9ae3a8 |
index e67068c..e69de29 100644
|
|
|
9ae3a8 |
--- a/tests/qapi-schema/missing-colon.out
|
|
|
9ae3a8 |
+++ b/tests/qapi-schema/missing-colon.out
|
|
|
9ae3a8 |
@@ -1,3 +0,0 @@
|
|
|
9ae3a8 |
-[OrderedDict([('enum', None), ('data', ['good', 'bad', 'ugly'])])]
|
|
|
9ae3a8 |
-[None]
|
|
|
9ae3a8 |
-[]
|
|
|
9ae3a8 |
diff --git a/tests/qapi-schema/missing-comma-list.err b/tests/qapi-schema/missing-comma-list.err
|
|
|
9ae3a8 |
index e69de29..4fe0700 100644
|
|
|
9ae3a8 |
--- a/tests/qapi-schema/missing-comma-list.err
|
|
|
9ae3a8 |
+++ b/tests/qapi-schema/missing-comma-list.err
|
|
|
9ae3a8 |
@@ -0,0 +1 @@
|
|
|
9ae3a8 |
+<stdin>:2:20: Expected "," or "]"
|
|
|
9ae3a8 |
diff --git a/tests/qapi-schema/missing-comma-list.exit b/tests/qapi-schema/missing-comma-list.exit
|
|
|
9ae3a8 |
index 573541a..d00491f 100644
|
|
|
9ae3a8 |
--- a/tests/qapi-schema/missing-comma-list.exit
|
|
|
9ae3a8 |
+++ b/tests/qapi-schema/missing-comma-list.exit
|
|
|
9ae3a8 |
@@ -1 +1 @@
|
|
|
9ae3a8 |
-0
|
|
|
9ae3a8 |
+1
|
|
|
9ae3a8 |
diff --git a/tests/qapi-schema/missing-comma-list.out b/tests/qapi-schema/missing-comma-list.out
|
|
|
9ae3a8 |
index e3bd904..e69de29 100644
|
|
|
9ae3a8 |
--- a/tests/qapi-schema/missing-comma-list.out
|
|
|
9ae3a8 |
+++ b/tests/qapi-schema/missing-comma-list.out
|
|
|
9ae3a8 |
@@ -1,3 +0,0 @@
|
|
|
9ae3a8 |
-[OrderedDict([('enum', 'Status'), ('data', ['good', 'bad', 'ugly'])])]
|
|
|
9ae3a8 |
-['Status']
|
|
|
9ae3a8 |
-[]
|
|
|
9ae3a8 |
diff --git a/tests/qapi-schema/missing-comma-object.err b/tests/qapi-schema/missing-comma-object.err
|
|
|
9ae3a8 |
index e69de29..b0121b5 100644
|
|
|
9ae3a8 |
--- a/tests/qapi-schema/missing-comma-object.err
|
|
|
9ae3a8 |
+++ b/tests/qapi-schema/missing-comma-object.err
|
|
|
9ae3a8 |
@@ -0,0 +1 @@
|
|
|
9ae3a8 |
+<stdin>:2:3: Expected "," or "}"
|
|
|
9ae3a8 |
diff --git a/tests/qapi-schema/missing-comma-object.exit b/tests/qapi-schema/missing-comma-object.exit
|
|
|
9ae3a8 |
index 573541a..d00491f 100644
|
|
|
9ae3a8 |
--- a/tests/qapi-schema/missing-comma-object.exit
|
|
|
9ae3a8 |
+++ b/tests/qapi-schema/missing-comma-object.exit
|
|
|
9ae3a8 |
@@ -1 +1 @@
|
|
|
9ae3a8 |
-0
|
|
|
9ae3a8 |
+1
|
|
|
9ae3a8 |
diff --git a/tests/qapi-schema/missing-comma-object.out b/tests/qapi-schema/missing-comma-object.out
|
|
|
9ae3a8 |
index e3bd904..e69de29 100644
|
|
|
9ae3a8 |
--- a/tests/qapi-schema/missing-comma-object.out
|
|
|
9ae3a8 |
+++ b/tests/qapi-schema/missing-comma-object.out
|
|
|
9ae3a8 |
@@ -1,3 +0,0 @@
|
|
|
9ae3a8 |
-[OrderedDict([('enum', 'Status'), ('data', ['good', 'bad', 'ugly'])])]
|
|
|
9ae3a8 |
-['Status']
|
|
|
9ae3a8 |
-[]
|
|
|
9ae3a8 |
diff --git a/tests/qapi-schema/trailing-comma-list.err b/tests/qapi-schema/trailing-comma-list.err
|
|
|
9ae3a8 |
index e69de29..ff839a3 100644
|
|
|
9ae3a8 |
--- a/tests/qapi-schema/trailing-comma-list.err
|
|
|
9ae3a8 |
+++ b/tests/qapi-schema/trailing-comma-list.err
|
|
|
9ae3a8 |
@@ -0,0 +1 @@
|
|
|
9ae3a8 |
+<stdin>:2:36: Expected "{", "[" or string
|
|
|
9ae3a8 |
diff --git a/tests/qapi-schema/trailing-comma-list.exit b/tests/qapi-schema/trailing-comma-list.exit
|
|
|
9ae3a8 |
index 573541a..d00491f 100644
|
|
|
9ae3a8 |
--- a/tests/qapi-schema/trailing-comma-list.exit
|
|
|
9ae3a8 |
+++ b/tests/qapi-schema/trailing-comma-list.exit
|
|
|
9ae3a8 |
@@ -1 +1 @@
|
|
|
9ae3a8 |
-0
|
|
|
9ae3a8 |
+1
|
|
|
9ae3a8 |
diff --git a/tests/qapi-schema/trailing-comma-list.out b/tests/qapi-schema/trailing-comma-list.out
|
|
|
9ae3a8 |
index e3bd904..e69de29 100644
|
|
|
9ae3a8 |
--- a/tests/qapi-schema/trailing-comma-list.out
|
|
|
9ae3a8 |
+++ b/tests/qapi-schema/trailing-comma-list.out
|
|
|
9ae3a8 |
@@ -1,3 +0,0 @@
|
|
|
9ae3a8 |
-[OrderedDict([('enum', 'Status'), ('data', ['good', 'bad', 'ugly'])])]
|
|
|
9ae3a8 |
-['Status']
|
|
|
9ae3a8 |
-[]
|
|
|
9ae3a8 |
diff --git a/tests/qapi-schema/trailing-comma-object.err b/tests/qapi-schema/trailing-comma-object.err
|
|
|
9ae3a8 |
index e69de29..f540962 100644
|
|
|
9ae3a8 |
--- a/tests/qapi-schema/trailing-comma-object.err
|
|
|
9ae3a8 |
+++ b/tests/qapi-schema/trailing-comma-object.err
|
|
|
9ae3a8 |
@@ -0,0 +1 @@
|
|
|
9ae3a8 |
+<stdin>:2:38: Expected string
|
|
|
9ae3a8 |
diff --git a/tests/qapi-schema/trailing-comma-object.exit b/tests/qapi-schema/trailing-comma-object.exit
|
|
|
9ae3a8 |
index 573541a..d00491f 100644
|
|
|
9ae3a8 |
--- a/tests/qapi-schema/trailing-comma-object.exit
|
|
|
9ae3a8 |
+++ b/tests/qapi-schema/trailing-comma-object.exit
|
|
|
9ae3a8 |
@@ -1 +1 @@
|
|
|
9ae3a8 |
-0
|
|
|
9ae3a8 |
+1
|
|
|
9ae3a8 |
diff --git a/tests/qapi-schema/trailing-comma-object.out b/tests/qapi-schema/trailing-comma-object.out
|
|
|
9ae3a8 |
index e3bd904..e69de29 100644
|
|
|
9ae3a8 |
--- a/tests/qapi-schema/trailing-comma-object.out
|
|
|
9ae3a8 |
+++ b/tests/qapi-schema/trailing-comma-object.out
|
|
|
9ae3a8 |
@@ -1,3 +0,0 @@
|
|
|
9ae3a8 |
-[OrderedDict([('enum', 'Status'), ('data', ['good', 'bad', 'ugly'])])]
|
|
|
9ae3a8 |
-['Status']
|
|
|
9ae3a8 |
-[]
|
|
|
9ae3a8 |
diff --git a/tests/qapi-schema/unclosed-list.err b/tests/qapi-schema/unclosed-list.err
|
|
|
9ae3a8 |
index f9a9c2a..0e837a7 100644
|
|
|
9ae3a8 |
--- a/tests/qapi-schema/unclosed-list.err
|
|
|
9ae3a8 |
+++ b/tests/qapi-schema/unclosed-list.err
|
|
|
9ae3a8 |
@@ -1 +1 @@
|
|
|
9ae3a8 |
-Crashed: <type 'exceptions.IndexError'>
|
|
|
9ae3a8 |
+<stdin>:1:20: Expected "," or "]"
|
|
|
9ae3a8 |
diff --git a/tests/qapi-schema/unclosed-object.err b/tests/qapi-schema/unclosed-object.err
|
|
|
9ae3a8 |
index f9a9c2a..e6dc950 100644
|
|
|
9ae3a8 |
--- a/tests/qapi-schema/unclosed-object.err
|
|
|
9ae3a8 |
+++ b/tests/qapi-schema/unclosed-object.err
|
|
|
9ae3a8 |
@@ -1 +1 @@
|
|
|
9ae3a8 |
-Crashed: <type 'exceptions.IndexError'>
|
|
|
9ae3a8 |
+<stdin>:1:21: Expected "," or "}"
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.11.7
|
|
|
9ae3a8 |
|