[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 25/58] json: Accept overlong \xC0\x80 as U+0000 ("mod
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PULL 25/58] json: Accept overlong \xC0\x80 as U+0000 ("modified UTF-8") |
Date: |
Fri, 24 Aug 2018 21:31:33 +0200 |
Since the JSON grammer doesn't accept U+0000 anywhere, this merely
exchanges one kind of parse error for another. It's purely for
consistency with qobject_to_json(), which accepts \xC0\x80 (see commit
e2ec3f97680).
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
---
qobject/json-lexer.c | 2 +-
qobject/json-parser.c | 2 +-
tests/check-qjson.c | 8 +-------
3 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c
index 93fa2737e6..4c402f62d3 100644
--- a/qobject/json-lexer.c
+++ b/qobject/json-lexer.c
@@ -93,7 +93,7 @@
* interpolation = %((l|ll|I64)[du]|[ipsf])
*
* Note:
- * - Input must be encoded in UTF-8.
+ * - Input must be encoded in modified UTF-8.
* - Decoding and validating is left to the parser.
*/
diff --git a/qobject/json-parser.c b/qobject/json-parser.c
index b77931614b..a9b227f56c 100644
--- a/qobject/json-parser.c
+++ b/qobject/json-parser.c
@@ -200,7 +200,7 @@ static QString *qstring_from_escaped_str(JSONParserContext
*ctxt,
}
} else {
cp = mod_utf8_codepoint(ptr, 6, &end);
- if (cp <= 0) {
+ if (cp < 0) {
parse_error(ctxt, token, "invalid UTF-8 sequence in string");
goto out;
}
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index 71c77d2f70..3abf12b4d2 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -152,12 +152,6 @@ static void string_with_quotes(void)
static void utf8_string(void)
{
/*
- * Problem: we can't easily deal with embedded U+0000. Parsing
- * the JSON string "this \\u0000" is fun" yields "this \0 is fun",
- * which gets misinterpreted as NUL-terminated "this ". We should
- * consider using overlong encoding \xC0\x80 for U+0000 ("modified
- * UTF-8").
- *
* Most test cases are scraped from Markus Kuhn's UTF-8 decoder
* capability and stress test at
* http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
@@ -586,7 +580,7 @@ static void utf8_string(void)
{
/* \U+0000 */
"\xC0\x80",
- NULL,
+ "\xC0\x80",
"\\u0000",
},
{
--
2.17.1
- [Qemu-devel] [PULL 04/58] check-qjson: Cover whitespace more thoroughly, (continued)
- [Qemu-devel] [PULL 04/58] check-qjson: Cover whitespace more thoroughly, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 03/58] check-qjson: Cover blank and lexically erroneous input, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 17/58] json: Fix lexer to include the bad character in JSON_ERROR token, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 06/58] qmp-test: Cover syntax and lexical errors, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 13/58] check-qjson: Simplify utf8_string(), Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 02/58] check-qjson: Cover multiple JSON objects in same string, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 20/58] json: Tighten and simplify qstring_from_escaped_str()'s loop, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 11/58] check-qjson: Consolidate partly redundant string tests, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 33/58] json: Have lexer call streamer directly, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 12/58] check-qjson: Cover UTF-8 in single quoted strings, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 25/58] json: Accept overlong \xC0\x80 as U+0000 ("modified UTF-8"),
Markus Armbruster <=
- [Qemu-devel] [PULL 01/58] docs/interop/qmp-spec: How to force known good parser state, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 15/58] check-qjson qmp-test: Cover control characters more thoroughly, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 16/58] check-qjson: Cover interpolation more thoroughly, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 10/58] check-qjson: Cover escaped characters more thoroughly, part 2, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 30/58] check-qjson: Fix and enable utf8_string()'s disabled part, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 28/58] json: Reject invalid \uXXXX, fix \u0000, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 39/58] json: Pass lexical errors and limit violations to callback, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 19/58] json: Revamp lexer documentation, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 23/58] json: Report first rather than last parse error, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 24/58] json: Leave rejecting invalid UTF-8 to parser, Markus Armbruster, 2018/08/24