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

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