aboutsummaryrefslogtreecommitdiff
path: root/tests/test-opts-visitor.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2017-03-03 13:32:46 +0100
committerMarkus Armbruster <armbru@redhat.com>2017-03-05 09:14:20 +0100
commita9416dc62c36079b93b4951c894a0b15e53bb38c (patch)
tree3c5af2b9ea8f6ec2a98b014a3a075d4c0ad47c6a /tests/test-opts-visitor.c
parenta4a1c70dc759e5b81627e96564f344ab43ea86eb (diff)
tests: Cover input visit beyond end of list
When you try to visit beyond the end of a list, the qobject input visitor crashes, and the string visitor screws returns garbage. The generated list visits never go beyond the list end, but manual visits could. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <1488544368-30622-27-git-send-email-armbru@redhat.com>
Diffstat (limited to 'tests/test-opts-visitor.c')
-rw-r--r--tests/test-opts-visitor.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/test-opts-visitor.c b/tests/test-opts-visitor.c
index b93fd330a8..2238f8efe5 100644
--- a/tests/test-opts-visitor.c
+++ b/tests/test-opts-visitor.c
@@ -210,6 +210,43 @@ test_opts_range_unvisited(void)
qemu_opts_del(opts);
}
+static void
+test_opts_range_beyond(void)
+{
+ Error *err = NULL;
+ intList *list = NULL;
+ intList *tail;
+ QemuOpts *opts;
+ Visitor *v;
+ int64_t val;
+
+ opts = qemu_opts_parse(qemu_find_opts("userdef"), "ilist=0", false,
+ &error_abort);
+
+ v = opts_visitor_new(opts);
+
+ visit_start_struct(v, NULL, NULL, 0, &error_abort);
+
+ /* Would be simpler if the visitor genuinely supported virtual walks */
+ visit_start_list(v, "ilist", (GenericList **)&list, sizeof(*list),
+ &error_abort);
+ tail = list;
+ visit_type_int(v, NULL, &tail->value, &error_abort);
+ g_assert_cmpint(tail->value, ==, 0);
+ tail = (intList *)visit_next_list(v, (GenericList *)tail, sizeof(*tail));
+ g_assert(!tail);
+ visit_type_int(v, NULL, &val, &err);
+ error_free_or_abort(&err);
+ visit_end_list(v, (void **)&list);
+
+ visit_check_struct(v, &error_abort);
+ visit_end_struct(v, NULL);
+
+ qapi_free_intList(list);
+ visit_free(v);
+ qemu_opts_del(opts);
+}
+
int
main(int argc, char **argv)
{
@@ -303,6 +340,8 @@ main(int argc, char **argv)
g_test_add_func("/visitor/opts/range/unvisited",
test_opts_range_unvisited);
+ g_test_add_func("/visitor/opts/range/beyond",
+ test_opts_range_beyond);
g_test_run();
return 0;