[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 14/60] check-qjson qmp-test: Cover control charac
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH v2 14/60] check-qjson qmp-test: Cover control characters more thoroughly |
Date: |
Fri, 17 Aug 2018 17:05:13 +0200 |
RFC 7159 requires control characters in strings to be escaped.
Demonstrate the JSON parser accepts U+0001 .. U+001F unescaped.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
tests/check-qjson.c | 36 ++++++++++++++++++++++++++++++------
tests/qmp-test.c | 14 ++++++++++++++
2 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index e81fbb95a3..1581fbf170 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -192,6 +192,26 @@ static void utf8_string(void)
* We may choose to define this as feature
*/
+ /* 0 Control characters */
+ {
+ /*
+ * Note: \x00 is impossible, other representations of
+ * U+0000 are covered under 4.3
+ */
+ "\x01\x02\x03\x04\x05\x06\x07"
+ "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
+ "\x10\x11\x12\x13\x14\x15\x16\x17"
+ "\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F",
+ /* bug: not corrected (valid UTF-8, but invalid JSON) */
+ "\x01\x02\x03\x04\x05\x06\x07"
+ "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
+ "\x10\x11\x12\x13\x14\x15\x16\x17"
+ "\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F",
+ "\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007"
+ "\\b\\t\\n\\u000B\\f\\r\\u000E\\u000F"
+ "\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017"
+ "\\u0018\\u0019\\u001A\\u001B\\u001C\\u001D\\u001E\\u001F",
+ },
/* 1 Some correct UTF-8 text */
{
/* a bit of German */
@@ -211,14 +231,14 @@ static void utf8_string(void)
/* 2 Boundary condition test cases */
/* 2.1 First possible sequence of a certain length */
/*
- * 2.1.1 1 byte U+0001
- * \x00 is impossible, test \x01 instead. Other
- * representations of U+0000 are covered under 4.3.
+ * 2.1.1 1 byte U+0020
+ * Control characters are already covered by their own test
+ * case under 0. Test the first 1 byte non-control character
+ * here.
*/
{
- "\x01",
- "\x01",
- "\\u0001",
+ " ",
+ " ",
},
/* 2.1.2 2 bytes U+0080 */
{
@@ -1333,6 +1353,10 @@ static void junk_input(void)
g_assert(!err); /* BUG */
g_assert(obj == NULL);
+ obj = qobject_from_json("{\x01", &err);
+ g_assert(!err); /* BUG */
+ g_assert(obj == NULL);
+
obj = qobject_from_json("[0\xFF]", &err);
error_free_or_abort(&err);
g_assert(obj == NULL);
diff --git a/tests/qmp-test.c b/tests/qmp-test.c
index 17153192fe..5edc97f63f 100644
--- a/tests/qmp-test.c
+++ b/tests/qmp-test.c
@@ -71,6 +71,13 @@ static void test_malformed(QTestState *qts)
qobject_unref(resp);
g_assert(recovered(qts));
+ /* lexical error: funny control character outside string */
+ qtest_qmp_send_raw(qts, "{\x01");
+ resp = qtest_qmp_receive(qts);
+ g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
+ qobject_unref(resp);
+ g_assert(recovered(qts));
+
/* lexical error: impossible byte in string */
qtest_qmp_send_raw(qts, "{'bad \xFF");
resp = qtest_qmp_receive(qts);
@@ -78,6 +85,13 @@ static void test_malformed(QTestState *qts)
qobject_unref(resp);
g_assert(recovered(qts));
+ /* lexical error: control character in string */
+ qtest_qmp_send_raw(qts, "{'execute': 'nonexistent', 'id':'\n'}");
+ resp = qtest_qmp_receive(qts);
+ g_assert_cmpstr(get_error_class(resp), ==, "CommandNotFound"); /* BUG */
+ qobject_unref(resp);
+ g_assert(recovered(qts));
+
/* lexical error: interpolation */
qtest_qmp_send_raw(qts, "%%p\n");
resp = qtest_qmp_receive(qts);
--
2.17.1
- [Qemu-devel] [PATCH v2 16/60] json: Fix lexer to include the bad character in JSON_ERROR token, (continued)
- [Qemu-devel] [PATCH v2 16/60] json: Fix lexer to include the bad character in JSON_ERROR token, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 12/60] check-qjson: Simplify utf8_string(), Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 08/60] check-qjson: Streamline escaped_string()'s test strings, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 02/60] check-qjson: Cover blank and lexically erroneous input, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 06/60] test-qga: Clean up how we test QGA synchronization, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 04/60] qmp-cmd-test: Split off qmp-test, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 05/60] qmp-test: Cover syntax and lexical errors, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 14/60] check-qjson qmp-test: Cover control characters more thoroughly,
Markus Armbruster <=
- [Qemu-devel] [PATCH v2 09/60] check-qjson: Cover escaped characters more thoroughly, part 2, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 42/60] json: Improve names of lexer states related to numbers, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 34/60] json: Don't pass null @tokens to json_parser_parse(), Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 23/60] json: Leave rejecting invalid UTF-8 to parser, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 30/60] json: remove useless return value from lexer/parser, Markus Armbruster, 2018/08/17
- [Qemu-devel] [PATCH v2 25/60] json: Leave rejecting invalid escape sequences to parser, Markus Armbruster, 2018/08/17
- [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