[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 13/60] check-qjson: Fix utf8_string() to test all
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH v2 13/60] check-qjson: Fix utf8_string() to test all invalid sequences |
Date: |
Fri, 17 Aug 2018 17:05:12 +0200 |
Some of utf8_string()'s test_cases[] contain multiple invalid
sequences. Testing that qobject_from_json() fails only tests we
reject at least one invalid sequence. That's incomplete.
Additionally test each non-space sequence in isolation.
This demonstrates that the JSON parser accepts invalid sequences
starting with \xC2..\xF4. Add a FIXME comment.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
tests/check-qjson.c | 33 ++++++++++++++++++++++++++++-----
1 file changed, 28 insertions(+), 5 deletions(-)
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index dd87a4962f..e81fbb95a3 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -20,6 +20,7 @@
#include "qapi/qmp/qnull.h"
#include "qapi/qmp/qnum.h"
#include "qapi/qmp/qstring.h"
+#include "qemu/unicode.h"
#include "qemu-common.h"
static QString *from_json_str(const char *jstr, Error **errp, bool single)
@@ -410,7 +411,7 @@ static void utf8_string(void)
"\xC8 \xC9 \xCA \xCB \xCC \xCD \xCE \xCF "
"\xD0 \xD1 \xD2 \xD3 \xD4 \xD5 \xD6 \xD7 "
"\xD8 \xD9 \xDA \xDB \xDC \xDD \xDE \xDF ",
- NULL, /* bug: rejected */
+ NULL, /* bug: rejected (partly, see FIXME below) */
"\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD "
"\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD "
"\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD "
@@ -429,7 +430,7 @@ static void utf8_string(void)
/* 3.2.3 All 8 first bytes of 4-byte sequences, followed by space */
{
"\xF0 \xF1 \xF2 \xF3 \xF4 \xF5 \xF6 \xF7 ",
- NULL, /* bug: rejected */
+ NULL, /* bug: rejected (partly, see FIXME below) */
"\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD ",
},
/* 3.2.4 All 4 first bytes of 5-byte sequences, followed by space */
@@ -509,7 +510,7 @@ static void utf8_string(void)
{
"\xC0\xE0\x80\xF0\x80\x80\xF8\x80\x80\x80\xFC\x80\x80\x80\x80"
"\xDF\xEF\xBF\xF7\xBF\xBF\xFB\xBF\xBF\xBF\xFD\xBF\xBF\xBF\xBF",
- NULL, /* bug: rejected */
+ NULL, /* bug: rejected (partly, see FIXME below) */
"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD"
"\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD",
},
@@ -792,8 +793,8 @@ static void utf8_string(void)
};
int i, j;
QString *str;
- const char *json_in, *utf8_out, *utf8_in, *json_out;
- char *jstr;
+ const char *json_in, *utf8_out, *utf8_in, *json_out, *tail;
+ char *end, *in, *jstr;
for (i = 0; test_cases[i].json_in; i++) {
for (j = 0; j < 2; j++) {
@@ -810,6 +811,28 @@ static void utf8_string(void)
} else {
str = from_json_str(json_in, NULL, j);
g_assert(!str);
+ /*
+ * Failure may be due to any sequence, but *all* sequences
+ * are expected to fail. Test each one in isolation.
+ */
+ for (tail = json_in; *tail; tail = end) {
+ mod_utf8_codepoint(tail, 6, &end);
+ if (*end == ' ') {
+ end++;
+ }
+ in = strndup(tail, end - tail);
+ str = from_json_str(in, NULL, j);
+ /*
+ * FIXME JSON parser accepts invalid sequence
+ * starting with \xC2..\xF4
+ */
+ if (*in >= '\xC2' && *in <= '\xF4') {
+ g_free(str);
+ str = NULL;
+ }
+ g_assert(!str);
+ g_free(in);
+ }
}
/* Unparse @utf8_in, expect @json_out */
--
2.17.1
- Re: [Qemu-devel] [PATCH v2 25/60] json: Leave rejecting invalid escape sequences to parser, (continued)
- [Qemu-devel] [PATCH v2 38/60] json: Pass lexical errors and limit violations to callback, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 44/60] json: Fix latent parser aborts at end of input, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 28/60] json: Fix \uXXXX for surrogate pairs, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 21/60] json: Reject invalid UTF-8 sequences, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 24/60] json: Accept overlong \xC0\x80 as U+0000 ("modified UTF-8"), Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 13/60] check-qjson: Fix utf8_string() to test all invalid sequences,
Markus Armbruster <=
- [Qemu-devel] [PATCH v2 18/60] json: Revamp lexer documentation, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 27/60] json: Reject invalid \uXXXX, fix \u0000, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 36/60] json: Rename token JSON_ESCAPE & friends to JSON_INTERPOL, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 52/60] json: Eliminate lexer state IN_WHITESPACE, pseudo-token JSON_SKIP, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 20/60] check-qjson: Document we expect invalid UTF-8 to be rejected, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 35/60] json: Don't create JSON_ERROR tokens that won't be used, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 37/60] json: Treat unwanted interpolation as lexical error, Markus Armbruster, 2018/08/17