mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-29 05:13:54 -06:00
qapi: Drop support for escape sequences other than \\
Since the previous commit restricted strings to printable ASCII, \uXXXX's only use is obfuscation. Drop it. This leaves \\, \/, \', and \". Since QAPI schema strings are all names, and names are restricted to ASCII letters, digits, hyphen, and underscore, none of them is useful. The latter three have no test coverage. Drop them. Keep \\ to avoid (more) gratuitous incompatibility with JSON. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20190913201349.24332-8-armbru@redhat.com>
This commit is contained in:
parent
56a8caff92
commit
9b4416bfc1
19 changed files with 7 additions and 60 deletions
|
@ -524,29 +524,9 @@ class QAPISchemaParser(object):
|
||||||
if ch == '\n':
|
if ch == '\n':
|
||||||
raise QAPIParseError(self, 'Missing terminating "\'"')
|
raise QAPIParseError(self, 'Missing terminating "\'"')
|
||||||
if esc:
|
if esc:
|
||||||
# Note: we don't recognize escape sequences
|
# Note: we recognize only \\ because we have
|
||||||
# for control characters
|
# no use for funny characters in strings
|
||||||
if ch == 'u':
|
if ch != '\\':
|
||||||
value = 0
|
|
||||||
for _ in range(0, 4):
|
|
||||||
ch = self.src[self.cursor]
|
|
||||||
self.cursor += 1
|
|
||||||
if ch not in '0123456789abcdefABCDEF':
|
|
||||||
raise QAPIParseError(self,
|
|
||||||
'\\u escape needs 4 '
|
|
||||||
'hex digits')
|
|
||||||
value = (value << 4) + int(ch, 16)
|
|
||||||
# If Python 2 and 3 didn't disagree so much on
|
|
||||||
# how to handle Unicode, then we could allow
|
|
||||||
# Unicode string defaults. But most of QAPI is
|
|
||||||
# ASCII-only, so we aren't losing much for now.
|
|
||||||
if not value or value > 0x7f:
|
|
||||||
raise QAPIParseError(self,
|
|
||||||
'For now, \\u escape '
|
|
||||||
'only supports non-zero '
|
|
||||||
'values up to \\u007f')
|
|
||||||
ch = chr(value)
|
|
||||||
elif ch not in '\\/\'"':
|
|
||||||
raise QAPIParseError(self,
|
raise QAPIParseError(self,
|
||||||
"Unknown escape \\%s" % ch)
|
"Unknown escape \\%s" % ch)
|
||||||
esc = False
|
esc = False
|
||||||
|
|
|
@ -374,9 +374,6 @@ qapi-schema += enum-int-member.json
|
||||||
qapi-schema += enum-member-case.json
|
qapi-schema += enum-member-case.json
|
||||||
qapi-schema += enum-missing-data.json
|
qapi-schema += enum-missing-data.json
|
||||||
qapi-schema += enum-wrong-data.json
|
qapi-schema += enum-wrong-data.json
|
||||||
qapi-schema += escape-outside-string.json
|
|
||||||
qapi-schema += escape-too-big.json
|
|
||||||
qapi-schema += escape-too-short.json
|
|
||||||
qapi-schema += event-boxed-empty.json
|
qapi-schema += event-boxed-empty.json
|
||||||
qapi-schema += event-case.json
|
qapi-schema += event-case.json
|
||||||
qapi-schema += event-member-invalid-dict.json
|
qapi-schema += event-member-invalid-dict.json
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
tests/qapi-schema/escape-outside-string.json:3:27: Stray "\"
|
|
|
@ -1 +0,0 @@
|
||||||
1
|
|
|
@ -1,3 +0,0 @@
|
||||||
# escape sequences are permitted only inside strings
|
|
||||||
# { 'command': 'foo', 'data': {} }
|
|
||||||
{ 'command': 'foo', 'data'\u003a{} }
|
|
|
@ -1 +0,0 @@
|
||||||
tests/qapi-schema/escape-too-big.json:3:14: For now, \u escape only supports non-zero values up to \u007f
|
|
|
@ -1 +0,0 @@
|
||||||
1
|
|
|
@ -1,3 +0,0 @@
|
||||||
# we don't support full Unicode strings, yet
|
|
||||||
# { 'command': 'é' }
|
|
||||||
{ 'command': '\u00e9' }
|
|
|
@ -1 +0,0 @@
|
||||||
tests/qapi-schema/escape-too-short.json:3:14: \u escape needs 4 hex digits
|
|
|
@ -1 +0,0 @@
|
||||||
1
|
|
|
@ -1,3 +0,0 @@
|
||||||
# the \u escape requires 4 hex digits
|
|
||||||
# { 'command': 'a' }
|
|
||||||
{ 'command': '\u61' }
|
|
|
@ -0,0 +1 @@
|
||||||
|
tests/qapi-schema/ident-with-escape.json:3:3: Unknown escape \u
|
|
@ -1 +1 @@
|
||||||
0
|
1
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# we allow escape sequences in strings, if they map back to ASCII
|
# we don't recognize any \ escapes other than \\ (tested elsewhere)
|
||||||
# { 'command': 'fooA', 'data': { 'bar1': 'str' } }
|
# { 'command': 'fooA', 'data': { 'bar1': 'str' } }
|
||||||
{ 'c\u006fmmand': '\u0066\u006f\u006FA',
|
{ 'c\u006fmmand': '\u0066\u006f\u006FA',
|
||||||
'd\u0061ta': { '\u0062\u0061\u00721': '\u0073\u0074\u0072' } }
|
'd\u0061ta': { '\u0062\u0061\u00721': '\u0073\u0074\u0072' } }
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
module None
|
|
||||||
object q_empty
|
|
||||||
enum QType
|
|
||||||
prefix QTYPE
|
|
||||||
member none
|
|
||||||
member qnull
|
|
||||||
member qnum
|
|
||||||
member qstring
|
|
||||||
member qdict
|
|
||||||
member qlist
|
|
||||||
member qbool
|
|
||||||
module ident-with-escape.json
|
|
||||||
object q_obj_fooA-arg
|
|
||||||
member bar1: str optional=False
|
|
||||||
command fooA q_obj_fooA-arg -> None
|
|
||||||
gen=True success_response=True boxed=False oob=False preconfig=False
|
|
|
@ -1,3 +1,3 @@
|
||||||
# we only recognize JSON escape sequences, plus our \' extension (no \x)
|
# we only recognize \\
|
||||||
# { 'command': 'foo', 'data': {} }
|
# { 'command': 'foo', 'data': {} }
|
||||||
{ 'command': 'foo', 'dat\x61':{} }
|
{ 'command': 'foo', 'dat\x61':{} }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue