Blame SOURCES/kvm-qapi.py-Reject-invalid-characters-in-schema-file.patch

0a122b
From b6e8e4d8b191e48d0a850eb6715ff2d70dd1ed8b Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <b6e8e4d8b191e48d0a850eb6715ff2d70dd1ed8b.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:15 +0100
0a122b
Subject: [PATCH 15/21] qapi.py: Reject invalid characters in schema file
0a122b
0a122b
RH-Author: Markus Armbruster <armbru@redhat.com>
0a122b
Message-id: <1386689361-30281-13-git-send-email-armbru@redhat.com>
0a122b
Patchwork-id: 56131
0a122b
O-Subject: [PATCH 7.0 qemu-kvm 12/18] qapi.py: Reject invalid characters in schema file
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
Signed-off-by: Markus Armbruster <armbru@redhat.com>
0a122b
Reviewed-by: Eric Blake <eblake@redhat.com>
0a122b
Message-id: 1374939721-7876-6-git-send-email-armbru@redhat.com
0a122b
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
0a122b
(cherry picked from commit 9213aa5391f7c8d3766420d96888f1353af4c890)
0a122b
0a122b
Backporting hack: need to unindent a comment in qapi-schem.json we got
0a122b
from commit 8707cd1 via v1.5.3.  The upstream trunk has the commit
0a122b
after the QAPI parser rewrite.  Indented comments just work there.
0a122b
The stable branch doesn't have the QAPI parser rewrite.  It works only
0a122b
because it silently ignores invalid characters.  Misfeature, cleaned
0a122b
up in this commit.
0a122b
0a122b
The comment will be reindented in the backport of the commit that
0a122b
makes indented comments work properly.
0a122b
---
0a122b
 qapi-schema.json                  | 2 +-
0a122b
 scripts/qapi.py                   | 2 ++
0a122b
 tests/qapi-schema/comments.err    | 1 +
0a122b
 tests/qapi-schema/comments.exit   | 2 +-
0a122b
 tests/qapi-schema/comments.out    | 3 ---
0a122b
 tests/qapi-schema/funny-char.err  | 1 +
0a122b
 tests/qapi-schema/funny-char.exit | 2 +-
0a122b
 tests/qapi-schema/funny-char.out  | 3 ---
0a122b
 8 files changed, 7 insertions(+), 9 deletions(-)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 qapi-schema.json                  | 2 +-
0a122b
 scripts/qapi.py                   | 2 ++
0a122b
 tests/qapi-schema/comments.err    | 1 +
0a122b
 tests/qapi-schema/comments.exit   | 2 +-
0a122b
 tests/qapi-schema/comments.out    | 3 ---
0a122b
 tests/qapi-schema/funny-char.err  | 1 +
0a122b
 tests/qapi-schema/funny-char.exit | 2 +-
0a122b
 tests/qapi-schema/funny-char.out  | 3 ---
0a122b
 8 files changed, 7 insertions(+), 9 deletions(-)
0a122b
0a122b
diff --git a/qapi-schema.json b/qapi-schema.json
0a122b
index b27108f..81fe591 100644
0a122b
--- a/qapi-schema.json
0a122b
+++ b/qapi-schema.json
0a122b
@@ -3437,7 +3437,7 @@
0a122b
                                        'spiceport' : 'ChardevSpicePort',
0a122b
                                        'vc'     : 'ChardevVC',
0a122b
                                        'ringbuf': 'ChardevRingbuf',
0a122b
-                                       # next one is just for compatibility
0a122b
+# next one is just for compatibility
0a122b
                                        'memory' : 'ChardevRingbuf' } }
0a122b
 
0a122b
 ##
0a122b
diff --git a/scripts/qapi.py b/scripts/qapi.py
0a122b
index 342d16c..0b48a1e 100644
0a122b
--- a/scripts/qapi.py
0a122b
+++ b/scripts/qapi.py
0a122b
@@ -101,6 +101,8 @@ class QAPISchema:
0a122b
                 if self.cursor == len(self.src):
0a122b
                     self.tok = None
0a122b
                     return
0a122b
+            elif not self.tok.isspace():
0a122b
+                raise QAPISchemaError(self, 'Stray "%s"' % self.tok)
0a122b
 
0a122b
     def get_members(self):
0a122b
         expr = OrderedDict()
0a122b
diff --git a/tests/qapi-schema/comments.err b/tests/qapi-schema/comments.err
0a122b
index e69de29..4a82b26 100644
0a122b
--- a/tests/qapi-schema/comments.err
0a122b
+++ b/tests/qapi-schema/comments.err
0a122b
@@ -0,0 +1 @@
0a122b
+<stdin>:2:33: Stray "#"
0a122b
diff --git a/tests/qapi-schema/comments.exit b/tests/qapi-schema/comments.exit
0a122b
index 573541a..d00491f 100644
0a122b
--- a/tests/qapi-schema/comments.exit
0a122b
+++ b/tests/qapi-schema/comments.exit
0a122b
@@ -1 +1 @@
0a122b
-0
0a122b
+1
0a122b
diff --git a/tests/qapi-schema/comments.out b/tests/qapi-schema/comments.out
0a122b
index e3bd904..e69de29 100644
0a122b
--- a/tests/qapi-schema/comments.out
0a122b
+++ b/tests/qapi-schema/comments.out
0a122b
@@ -1,3 +0,0 @@
0a122b
-[OrderedDict([('enum', 'Status'), ('data', ['good', 'bad', 'ugly'])])]
0a122b
-['Status']
0a122b
-[]
0a122b
diff --git a/tests/qapi-schema/funny-char.err b/tests/qapi-schema/funny-char.err
0a122b
index e69de29..d3dd293 100644
0a122b
--- a/tests/qapi-schema/funny-char.err
0a122b
+++ b/tests/qapi-schema/funny-char.err
0a122b
@@ -0,0 +1 @@
0a122b
+<stdin>:2:36: Stray ";"
0a122b
diff --git a/tests/qapi-schema/funny-char.exit b/tests/qapi-schema/funny-char.exit
0a122b
index 573541a..d00491f 100644
0a122b
--- a/tests/qapi-schema/funny-char.exit
0a122b
+++ b/tests/qapi-schema/funny-char.exit
0a122b
@@ -1 +1 @@
0a122b
-0
0a122b
+1
0a122b
diff --git a/tests/qapi-schema/funny-char.out b/tests/qapi-schema/funny-char.out
0a122b
index e3bd904..e69de29 100644
0a122b
--- a/tests/qapi-schema/funny-char.out
0a122b
+++ b/tests/qapi-schema/funny-char.out
0a122b
@@ -1,3 +0,0 @@
0a122b
-[OrderedDict([('enum', 'Status'), ('data', ['good', 'bad', 'ugly'])])]
0a122b
-['Status']
0a122b
-[]
0a122b
-- 
0a122b
1.7.11.7
0a122b