[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 24/56] json: Accept overlong \xC0\x80 as U+0000 ("mo
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH 24/56] json: Accept overlong \xC0\x80 as U+0000 ("modified UTF-8") |
Date: |
Wed, 8 Aug 2018 14:03:02 +0200 |
This is consistent with qobject_to_json(). See commit e2ec3f97680.
Signed-off-by: Markus Armbruster <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 ca1e0e2c03..36fb665b12 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 b3a95be3c8..14225c3c09 100644
--- a/qobject/json-parser.c
+++ b/qobject/json-parser.c
@@ -199,7 +199,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 e00be5b023..e5a7cb6bf6 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -121,12 +121,6 @@ static void escaped_string(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
@@ -555,7 +549,7 @@ static void utf8_string(void)
{
/* \U+0000 */
"\xC0\x80",
- NULL,
+ "\xC0\x80",
"\\u0000",
},
{
--
2.17.1
[Qemu-devel] [PATCH 28/56] json: Fix \uXXXX for surrogate pairs, Markus Armbruster, 2018/08/08