From nobody Tue Feb 10 00:58:13 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488304431688535.0646928512657; Tue, 28 Feb 2017 09:53:51 -0800 (PST) Received: from localhost ([::1]:35986 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cilyA-0006yO-Ha for importer@patchew.org; Tue, 28 Feb 2017 12:53:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cilkI-0003fg-8l for qemu-devel@nongnu.org; Tue, 28 Feb 2017 12:39:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cilkF-0005T0-7Q for qemu-devel@nongnu.org; Tue, 28 Feb 2017 12:39:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56674) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cilkE-0005RZ-RT for qemu-devel@nongnu.org; Tue, 28 Feb 2017 12:39:27 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ECBCF4E4C8 for ; Tue, 28 Feb 2017 17:39:26 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7CA2130661; Tue, 28 Feb 2017 17:39:26 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5E05D11384AE; Tue, 28 Feb 2017 18:39:20 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 28 Feb 2017 18:39:18 +0100 Message-Id: <1488303560-18803-25-git-send-email-armbru@redhat.com> In-Reply-To: <1488303560-18803-1-git-send-email-armbru@redhat.com> References: <1488303560-18803-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 28 Feb 2017 17:39:26 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 24/26] tests: Cover input visit beyond end of list X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Eric Blake --- tests/test-opts-visitor.c | 39 ++++++++++++++++++++++++++++++++++= ++++ tests/test-qobject-input-visitor.c | 10 ++++++++++ tests/test-string-input-visitor.c | 16 ++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/tests/test-opts-visitor.c b/tests/test-opts-visitor.c index b93fd33..2238f8e 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); } =20 +static void +test_opts_range_beyond(void) +{ + Error *err =3D NULL; + intList *list =3D NULL; + intList *tail; + QemuOpts *opts; + Visitor *v; + int64_t val; + + opts =3D qemu_opts_parse(qemu_find_opts("userdef"), "ilist=3D0", false, + &error_abort); + + v =3D 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 =3D list; + visit_type_int(v, NULL, &tail->value, &error_abort); + g_assert_cmpint(tail->value, =3D=3D, 0); + tail =3D (intList *)visit_next_list(v, (GenericList *)tail, sizeof(*ta= il)); + 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) =20 g_test_add_func("/visitor/opts/range/unvisited", test_opts_range_unvisited); + g_test_add_func("/visitor/opts/range/beyond", + test_opts_range_beyond); =20 g_test_run(); return 0; diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-= visitor.c index 87d4a77..8011baa 100644 --- a/tests/test-qobject-input-visitor.c +++ b/tests/test-qobject-input-visitor.c @@ -948,6 +948,16 @@ static void test_visitor_in_fail_list(TestInputVisitor= Data *data, visit_check_list(v, &err); error_free_or_abort(&err); visit_end_list(v, NULL); + + /* Visit beyond end of list */ + v =3D visitor_input_test_init(data, "[]"); + + visit_start_list(v, NULL, NULL, 0, &error_abort); +#if 0 /* FIXME crash */ + visit_type_int(v, NULL, &i64, &err); + error_free_or_abort(&err); +#endif + visit_end_list(v, NULL); } =20 static void test_visitor_in_fail_list_nested(TestInputVisitorData *data, diff --git a/tests/test-string-input-visitor.c b/tests/test-string-input-vi= sitor.c index fbe380a..6db850b 100644 --- a/tests/test-string-input-visitor.c +++ b/tests/test-string-input-visitor.c @@ -123,6 +123,7 @@ static void test_visitor_in_intList(TestInputVisitorDat= a *data, int64List *res =3D NULL; int64List *tail; Visitor *v; + int64_t val; =20 /* Valid lists */ =20 @@ -175,6 +176,21 @@ static void test_visitor_in_intList(TestInputVisitorDa= ta *data, visit_end_list(v, (void **)&res); =20 qapi_free_int64List(res); + + /* Visit beyond end of list */ + v =3D visitor_input_test_init(data, "0"); + + visit_start_list(v, NULL, (GenericList **)&res, sizeof(*res), + &error_abort); + tail =3D res; + visit_type_int64(v, NULL, &tail->value, &err); + g_assert_cmpint(tail->value, =3D=3D, 0); + visit_type_int64(v, NULL, &val, &err); + g_assert_cmpint(val, =3D=3D, 1); /* BUG */ + visit_check_list(v, &error_abort); + visit_end_list(v, (void **)&res); + + qapi_free_int64List(res); } =20 static void test_visitor_in_bool(TestInputVisitorData *data, --=20 2.7.4