From patchwork Tue Mar 21 03:17:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9635905 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9531F601E9 for ; Tue, 21 Mar 2017 03:19:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8825C27C2D for ; Tue, 21 Mar 2017 03:19:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D21327CEA; Tue, 21 Mar 2017 03:19:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DAEEA27C2D for ; Tue, 21 Mar 2017 03:19:56 +0000 (UTC) Received: from localhost ([::1]:36396 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqAKw-0003FG-Ig for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Mar 2017 23:19:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39519) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqAIQ-0001YZ-Hs for qemu-devel@nongnu.org; Mon, 20 Mar 2017 23:17:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cqAIN-0000RR-Tt for qemu-devel@nongnu.org; Mon, 20 Mar 2017 23:17:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54562) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cqAIN-0000Qq-MC; Mon, 20 Mar 2017 23:17:15 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A4BB9C00AFBC; Tue, 21 Mar 2017 03:17:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A4BB9C00AFBC Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A4BB9C00AFBC Received: from red.redhat.com (ovpn-121-124.rdu2.redhat.com [10.10.121.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8AAA78DD3; Tue, 21 Mar 2017 03:17:14 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 20 Mar 2017 22:17:05 -0500 Message-Id: <20170321031705.22291-3-eblake@redhat.com> In-Reply-To: <20170321031705.22291-1-eblake@redhat.com> References: <20170321031705.22291-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 21 Mar 2017 03:17:15 +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 2/2] qapi: Fix QemuOpts visitor regression on unvisited input 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: , Cc: lvivier@redhat.com, Michael Roth , armbru@redhat.com, qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP An off-by-one in commit 15c2f669e meant that we were failing to check for unparsed input in all QemuOpts visitors. Recent testsuite additions show that fixing the obvious bug with bogus fields will also fix the case of an incomplete list visit; update the tests to match the new behavior. Simple testcase: ./x86_64-softmmu/qemu-system-x86_64 -nodefaults -nographic -qmp stdio -numa node,size=1g failed to diagnose that 'size' is not a valid argument to -numa, and now once again reports: qemu-system-x86_64: -numa node,size=1g: Invalid parameter 'size' CC: qemu-stable@nongnu.org Signed-off-by: Eric Blake Reviewed-by: Michael Roth Tested-by: Laurent Vivier --- qapi/opts-visitor.c | 6 +++--- tests/test-opts-visitor.c | 15 +++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index 026d25b..b54da81 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -164,7 +164,7 @@ opts_check_struct(Visitor *v, Error **errp) GHashTableIter iter; GQueue *any; - if (ov->depth > 0) { + if (ov->depth > 1) { return; } @@ -276,8 +276,8 @@ static void opts_check_list(Visitor *v, Error **errp) { /* - * FIXME should set error when unvisited elements remain. Mostly - * harmless, as the generated visits always visit all elements. + * Unvisited list elements will be reported later when checking if + * unvisited struct members remain. */ } diff --git a/tests/test-opts-visitor.c b/tests/test-opts-visitor.c index a47c344..1766919 100644 --- a/tests/test-opts-visitor.c +++ b/tests/test-opts-visitor.c @@ -175,6 +175,7 @@ expect_u64_max(OptsVisitorFixture *f, gconstpointer test_data) static void test_opts_range_unvisited(void) { + Error *err = NULL; intList *list = NULL; intList *tail; QemuOpts *opts; @@ -199,10 +200,11 @@ test_opts_range_unvisited(void) g_assert_cmpint(tail->value, ==, 1); tail = (intList *)visit_next_list(v, (GenericList *)tail, sizeof(*list)); g_assert(tail); - visit_check_list(v, &error_abort); /* BUG: unvisited tail not reported */ + visit_check_list(v, &error_abort); /* unvisited tail ignored until... */ visit_end_list(v, (void **)&list); - visit_check_struct(v, &error_abort); + visit_check_struct(v, &err); /* ...here */ + error_free_or_abort(&err); visit_end_struct(v, NULL); qapi_free_intList(list); @@ -239,7 +241,7 @@ test_opts_range_beyond(void) error_free_or_abort(&err); visit_end_list(v, (void **)&list); - visit_check_struct(v, &error_abort); + visit_check_struct(v, &err); visit_end_struct(v, NULL); qapi_free_intList(list); @@ -250,6 +252,7 @@ test_opts_range_beyond(void) static void test_opts_dict_unvisited(void) { + Error *err = NULL; QemuOpts *opts; Visitor *v; UserDefOptions *userdef; @@ -258,11 +261,11 @@ test_opts_dict_unvisited(void) &error_abort); v = opts_visitor_new(opts); - /* FIXME: bogus should be diagnosed */ - visit_type_UserDefOptions(v, NULL, &userdef, &error_abort); + visit_type_UserDefOptions(v, NULL, &userdef, &err); + error_free_or_abort(&err); visit_free(v); qemu_opts_del(opts); - qapi_free_UserDefOptions(userdef); + g_assert(!userdef); } int