[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 14/58] check-qjson: Fix utf8_string() to test all
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH v3 14/58] check-qjson: Fix utf8_string() to test all invalid sequences |
Date: |
Thu, 23 Aug 2018 18:39:41 +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 8d0fe4c8a7..40a573eb21 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, bool single, Error **errp)
@@ -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, j, NULL);
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, j, NULL);
+ /*
+ * 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
- [Qemu-devel] [PATCH v3 04/58] check-qjson: Cover whitespace more thoroughly, (continued)
- [Qemu-devel] [PATCH v3 04/58] check-qjson: Cover whitespace more thoroughly, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 13/58] check-qjson: Simplify utf8_string(), Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 32/58] json-parser: simplify and avoid JSONParserContext allocation, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 30/58] check-qjson: Fix and enable utf8_string()'s disabled part, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 08/58] check-qjson: Cover escaped characters more thoroughly, part 1, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 07/58] test-qga: Clean up how we test QGA synchronization, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 15/58] check-qjson qmp-test: Cover control characters more thoroughly, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 24/58] json: Leave rejecting invalid UTF-8 to parser, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 05/58] qmp-cmd-test: Split off qmp-test, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 23/58] json: Report first rather than last parse error, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 14/58] check-qjson: Fix utf8_string() to test all invalid sequences,
Markus Armbruster <=
- [Qemu-devel] [PATCH v3 11/58] check-qjson: Consolidate partly redundant string tests, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 01/58] docs/interop/qmp-spec: How to force known good parser state, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 20/58] json: Tighten and simplify qstring_from_escaped_str()'s loop, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 09/58] check-qjson: Streamline escaped_string()'s test strings, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 02/58] check-qjson: Cover multiple JSON objects in same string, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 03/58] check-qjson: Cover blank and lexically erroneous input, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 06/58] qmp-test: Cover syntax and lexical errors, Markus Armbruster, 2018/08/23
- [Qemu-devel] [PATCH v3 49/58] json: Streamline json_message_process_token(), Markus Armbruster, 2018/08/23