aboutsummaryrefslogtreecommitdiff
path: root/tests/check-qjson.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2018-08-23 18:39:29 +0200
committerMarkus Armbruster <armbru@redhat.com>2018-08-24 20:25:48 +0200
commit956a104a6ccbc7c5599b84e05d9c438ca85623f8 (patch)
tree47c394a3525a1ad642737b8d7997f42e5f3b8da2 /tests/check-qjson.c
parent72e9e569d03c826641eada68d291971d165460bc (diff)
check-qjson: Cover multiple JSON objects in same string
qobject_from_json() & friends misbehave when the JSON text has more than one JSON value. Add test coverage to demonstrate the bugs. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20180823164025.12553-3-armbru@redhat.com>
Diffstat (limited to 'tests/check-qjson.c')
-rw-r--r--tests/check-qjson.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index eaf5d20663..cc952c56ea 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -1418,6 +1418,25 @@ static void limits_nesting(void)
g_assert(obj == NULL);
}
+static void multiple_values(void)
+{
+ Error *err = NULL;
+ QObject *obj;
+
+ /* BUG this leaks the syntax tree for "false" */
+ obj = qobject_from_json("false true", &err);
+ g_assert(qbool_get_bool(qobject_to(QBool, obj)));
+ g_assert(!err);
+ qobject_unref(obj);
+
+ /* BUG simultaneously succeeds and fails */
+ /* BUG calls json_parser_parse() with errp pointing to non-null */
+ obj = qobject_from_json("} true", &err);
+ g_assert(qbool_get_bool(qobject_to(QBool, obj)));
+ error_free_or_abort(&err);
+ qobject_unref(obj);
+}
+
int main(int argc, char **argv)
{
g_test_init(&argc, &argv, NULL);
@@ -1455,6 +1474,7 @@ int main(int argc, char **argv)
g_test_add_func("/errors/invalid_dict_comma", invalid_dict_comma);
g_test_add_func("/errors/unterminated/literal", unterminated_literal);
g_test_add_func("/errors/limits/nesting", limits_nesting);
+ g_test_add_func("/errors/multiple_values", multiple_values);
return g_test_run();
}