[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 03/58] check-qjson: Cover blank and lexically erroneo
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PULL 03/58] check-qjson: Cover blank and lexically erroneous input |
Date: |
Fri, 24 Aug 2018 21:31:11 +0200 |
qobject_from_json() can return null without setting an error on
lexical errors. I call that a bug. Add test coverage to demonstrate
it.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
---
tests/check-qjson.c | 40 +++++++++++++++++++++++++++++++++++++---
1 file changed, 37 insertions(+), 3 deletions(-)
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index cc952c56ea..4daadc272b 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -1307,8 +1307,40 @@ static void simple_varargs(void)
static void empty_input(void)
{
- const char *empty = "";
- QObject *obj = qobject_from_json(empty, &error_abort);
+ QObject *obj = qobject_from_json("", &error_abort);
+ g_assert(obj == NULL);
+}
+
+static void blank_input(void)
+{
+ QObject *obj = qobject_from_json("\n ", &error_abort);
+ g_assert(obj == NULL);
+}
+
+static void junk_input(void)
+{
+ /* Note: junk within strings is covered elsewhere */
+ Error *err = NULL;
+ QObject *obj;
+
+ obj = qobject_from_json("@", &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);
+
+ obj = qobject_from_json("00", &err);
+ g_assert(!err); /* BUG */
+ g_assert(obj == NULL);
+
+ obj = qobject_from_json("[1e", &err);
+ g_assert(!err); /* BUG */
+ g_assert(obj == NULL);
+
+ obj = qobject_from_json("truer", &err);
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}
@@ -1462,7 +1494,9 @@ int main(int argc, char **argv)
g_test_add_func("/varargs/simple_varargs", simple_varargs);
- g_test_add_func("/errors/empty_input", empty_input);
+ g_test_add_func("/errors/empty", empty_input);
+ g_test_add_func("/errors/blank", blank_input);
+ g_test_add_func("/errors/junk", junk_input);
g_test_add_func("/errors/unterminated/string", unterminated_string);
g_test_add_func("/errors/unterminated/escape", unterminated_escape);
g_test_add_func("/errors/unterminated/sq_string", unterminated_sq_string);
--
2.17.1
- [Qemu-devel] [PULL 00/58] QObject patches for 2018-08-24, Markus Armbruster, 2018/08/24
- [Qemu-devel] [PULL 07/58] test-qga: Clean up how we test QGA synchronization, Markus Armbruster, 2018/08/24
- [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 <=
- [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, 2018/08/24
- [Qemu-devel] [PULL 01/58] docs/interop/qmp-spec: How to force known good parser state, Markus Armbruster, 2018/08/24