yeahuh / rpms / qemu-kvm

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