From nobody Thu May 2 19:56:55 2024 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.zohomail.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 1500059535415520.9600397496127; Fri, 14 Jul 2017 12:12:15 -0700 (PDT) Received: from localhost ([::1]:39556 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW60Z-0005xg-37 for importer@patchew.org; Fri, 14 Jul 2017 15:12:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5x3-0002Hv-Ge for qemu-devel@nongnu.org; Fri, 14 Jul 2017 15:08:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW5x2-00021A-Hk for qemu-devel@nongnu.org; Fri, 14 Jul 2017 15:08:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57946) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dW5x2-00020v-8q for qemu-devel@nongnu.org; Fri, 14 Jul 2017 15:08:32 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4F76A3C33; Fri, 14 Jul 2017 19:08:31 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1B245D966; Fri, 14 Jul 2017 19:08:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4F76A3C33 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4F76A3C33 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 14:08:23 -0500 Message-Id: <20170714190827.4083-2-eblake@redhat.com> In-Reply-To: <20170714190827.4083-1-eblake@redhat.com> References: <20170714190827.4083-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 14 Jul 2017 19:08:31 +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 1/5] qapi: Further enhance visitor virtual walk doc example 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: armbru@redhat.com, Michael Roth 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" Markus pointed out that the example given for virtual walks did not discuss how to do a virtual walk of an alternate type. It turns out that for output, we don't need to visit an alternate (just directly visit the type that we want); and for input, visit_start_alternate() is not currently wired up for alternates (it requires a QAPI type, rather than permitting NULL for a virtual walk). Also, the example was never updated in commit 3b098d5 about where visit_complete() would fit in. Improve the description and example to give more details along these lines. Signed-off-by: Eric Blake --- include/qapi/visitor.h | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index 74768aa..b0a048f 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -183,19 +183,25 @@ * * It is also possible to use the visitors to do a virtual walk, where * no actual QAPI struct is present. In this situation, decisions - * about what needs to be walked are made by the calling code, and - * structured visits are split between pairs of start and end methods - * (where the end method must be called if the start function - * succeeded, even if an intermediate visit encounters an error). - * Thus, a virtual walk corresponding to '{ "list": [1, 2] }' looks - * like: + * about what needs to be walked are made by the calling code (that + * is, there is no use for QAPI alternate types in a virtual walk, + * because the code can just directly visit the appropriate type + * within the alternate), and structured visits are split between + * pairs of start and end methods (where the end method must be called + * if the start function succeeded, even if an intermediate visit + * encounters an error). Thus, a virtual output walk of an object + * containing a list of alternates between an integer or nested + * object, corresponding to '{ "list": [1, { "value": "2" } ] }', + * would look like: * * * Visitor *v; * Error *err =3D NULL; - * int value; + * int i =3D 1; + * const char *s =3D "2"; + * FOO output; * - * v =3D FOO_visitor_new(...); + * v =3D FOO_visitor_new(..., &output); * visit_start_struct(v, NULL, NULL, 0, &err); * if (err) { * goto out; @@ -204,16 +210,21 @@ * if (err) { * goto outobj; * } - * value =3D 1; - * visit_type_int(v, NULL, &value, &err); + * visit_type_int(v, NULL, &i, &err); * if (err) { * goto outlist; * } - * value =3D 2; - * visit_type_int(v, NULL, &value, &err); + * visit_type_start(v, NULL, NULL, 0, &err); * if (err) { - * goto outlist; + * goto outnest; + * } + * visit_type_str(v, "value", (char **)&s, &err); + * if (err) { + * goto outnest; * } + * visit_check_struct(v, &err); + * outnest: + * visit_end_struct(v, NULL); * outlist: * visit_end_list(v, NULL); * if (!err) { @@ -221,6 +232,10 @@ * } * outobj: * visit_end_struct(v, NULL); + * if (!err) { + * visit_complete(v, &output); + * ...use output... + * } * out: * error_propagate(errp, err); * visit_free(v); --=20 2.9.4 From nobody Thu May 2 19:56:55 2024 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.zohomail.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 1500059425726772.8256896113362; Fri, 14 Jul 2017 12:10:25 -0700 (PDT) Received: from localhost ([::1]:39546 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5yn-0004N9-9J for importer@patchew.org; Fri, 14 Jul 2017 15:10:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54177) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5x4-0002J2-Dp for qemu-devel@nongnu.org; Fri, 14 Jul 2017 15:08:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW5x3-00021R-AV for qemu-devel@nongnu.org; Fri, 14 Jul 2017 15:08:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55546) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dW5x3-000216-20 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 15:08:33 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 21FF4356BF5; Fri, 14 Jul 2017 19:08:32 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 856E65D966; Fri, 14 Jul 2017 19:08:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 21FF4356BF5 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 21FF4356BF5 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 14:08:24 -0500 Message-Id: <20170714190827.4083-3-eblake@redhat.com> In-Reply-To: <20170714190827.4083-1-eblake@redhat.com> References: <20170714190827.4083-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 14 Jul 2017 19:08:32 +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/5] tests: Enhance qobject output to cover partial visit 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: armbru@redhat.com, Michael Roth 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" Add a test that proves (at least when run under valgrind) that we are correctly handling allocated memory even when a visit is aborted in the middle for whatever other reason. See commit f24582d "qapi: fix double free in qmp_output_visitor_cleanup()" for a fix that was lacking testsuite exposure prior to this patch. Signed-off-by: Eric Blake --- tests/test-qobject-output-visitor.c | 46 +++++++++++++++++++++++++++++++++= +++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index 749c540..1e9a5d1 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -1,7 +1,7 @@ /* * QObject Output Visitor unit-tests. * - * Copyright (C) 2011-2016 Red Hat Inc. + * Copyright (C) 2011-2017 Red Hat Inc. * * Authors: * Luiz Capitulino @@ -251,6 +251,48 @@ static void test_visitor_out_struct_errors(TestOutputV= isitorData *data, } +static void test_visitor_out_partial_visit(TestOutputVisitorData *data, + const void *unused) +{ + /* Various checks that a mid-visit abort doesn't leak or double-free. = */ + const char *str =3D "hi"; + Error *err =3D NULL; + UserDefAlternate uda =3D { + .type =3D QTYPE_QDICT, + .u.udfu =3D { .integer =3D 1, + .string =3D (char *) "bye", + .enum1 =3D -1 } /* intentionally bad */ + }; + UserDefAlternate *obj =3D &uda; + + /* Abort within a nested object with no data members */ + visit_start_struct(data->ov, NULL, NULL, 0, &error_abort); + visit_start_struct(data->ov, "nested", NULL, 0, &error_abort); + visitor_reset(data); + + /* Abort in the middle of a list of strings */ + visit_start_list(data->ov, "list", NULL, 0, &error_abort); + visit_type_str(data->ov, NULL, (char **)&str, &error_abort); + visit_type_str(data->ov, NULL, (char **)&str, &error_abort); + visitor_reset(data); + + /* + * Abort in the middle of an alternate. Alternates can't be + * virtually visited, so we get to inline the first half of + * visit_type_UserDefAlternate(). + */ + visit_start_alternate(data->ov, NULL, (GenericAlternate **)&obj, + sizeof(uda), &error_abort); + visit_start_struct(data->ov, NULL, NULL, 0, &error_abort); + visit_type_UserDefUnionBase_members(data->ov, + (UserDefUnionBase *)&uda.u.udfu, + &err); + /* error expected because of bad "enum1" discriminator value */ + error_free_or_abort(&err); + visitor_reset(data); +} + + static void test_visitor_out_list(TestOutputVisitorData *data, const void *unused) { @@ -815,6 +857,8 @@ int main(int argc, char **argv) &out_visitor_data, test_visitor_out_struct_nes= ted); output_visitor_test_add("/visitor/output/struct-errors", &out_visitor_data, test_visitor_out_struct_err= ors); + output_visitor_test_add("/visitor/output/partial-visit", + &out_visitor_data, test_visitor_out_partial_vi= sit); output_visitor_test_add("/visitor/output/list", &out_visitor_data, test_visitor_out_list); output_visitor_test_add("/visitor/output/any", --=20 2.9.4 From nobody Thu May 2 19:56:55 2024 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.zohomail.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 1500059425572778.8119693422252; Fri, 14 Jul 2017 12:10:25 -0700 (PDT) Received: from localhost ([::1]:39545 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5ym-0004Lb-5G for importer@patchew.org; Fri, 14 Jul 2017 15:10:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54182) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5x4-0002K1-UU for qemu-devel@nongnu.org; Fri, 14 Jul 2017 15:08:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW5x4-00021h-1G for qemu-devel@nongnu.org; Fri, 14 Jul 2017 15:08:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59596) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dW5x3-00021L-Rt for qemu-devel@nongnu.org; Fri, 14 Jul 2017 15:08:33 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EA1B22C7311; Fri, 14 Jul 2017 19:08:32 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59DAD5D966; Fri, 14 Jul 2017 19:08:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EA1B22C7311 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EA1B22C7311 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 14:08:25 -0500 Message-Id: <20170714190827.4083-4-eblake@redhat.com> In-Reply-To: <20170714190827.4083-1-eblake@redhat.com> References: <20170714190827.4083-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 14 Jul 2017 19:08:33 +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 3/5] qapi: Visitor documentation tweak 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: armbru@redhat.com, Michael Roth 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" Make it clear that the name parameter to visit_start_struct() has the same semantics as for visit_start_int(). Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster --- include/qapi/visitor.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index b0a048f..dc09cc7 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -60,13 +60,13 @@ * visitors are declared here; the remaining visitors are generated in * qapi-visit.h. * - * The @name parameter of visit_type_FOO() describes the relation - * between this QAPI value and its parent container. When visiting - * the root of a tree, @name is ignored; when visiting a member of an - * object, @name is the key associated with the value; when visiting a - * member of a list, @name is NULL; and when visiting the member of an - * alternate, @name should equal the name used for visiting the - * alternate. + * The @name parameter of visit_type_FOO() and visit_start_OBJECT() + * describes the relation between this QAPI value and its parent + * container. When visiting the root of a tree, @name is ignored; + * when visiting a member of an object, @name is the key associated + * with the value; when visiting a member of a list, @name is NULL; + * and when visiting the member of an alternate, @name should equal + * the name used for visiting the alternate. * * The visit_type_FOO() functions expect a non-null @obj argument; * they allocate *@obj during input visits, leave it unchanged on --=20 2.9.4 From nobody Thu May 2 19:56:55 2024 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.zohomail.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 1500059536232139.25929846965153; Fri, 14 Jul 2017 12:12:16 -0700 (PDT) Received: from localhost ([::1]:39557 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW60b-0005zM-Tj for importer@patchew.org; Fri, 14 Jul 2017 15:12:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54197) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5x5-0002M5-Qc for qemu-devel@nongnu.org; Fri, 14 Jul 2017 15:08:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW5x4-000222-SS for qemu-devel@nongnu.org; Fri, 14 Jul 2017 15:08:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53722) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dW5x4-00021f-Ly for qemu-devel@nongnu.org; Fri, 14 Jul 2017 15:08:34 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A06C1D5709 for ; Fri, 14 Jul 2017 19:08:33 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D1175D966; Fri, 14 Jul 2017 19:08:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A06C1D5709 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A06C1D5709 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 14:08:26 -0500 Message-Id: <20170714190827.4083-5-eblake@redhat.com> In-Reply-To: <20170714190827.4083-1-eblake@redhat.com> References: <20170714190827.4083-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 14 Jul 2017 19:08:33 +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 4/5] qtest: Avoid passing raw strings through hmp() 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: armbru@redhat.com 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" The next patch will add __attribute__((__format__)) to hmp(), which in turn causes gcc to warn about non-literal format strings. Rather than risk an arbitrary string containing % being mis-handled, always pass variable strings along with a %s format. Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster --- tests/test-hmp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-hmp.c b/tests/test-hmp.c index d77b3c8..0af0664 100644 --- a/tests/test-hmp.c +++ b/tests/test-hmp.c @@ -80,7 +80,7 @@ static void test_commands(void) if (verbose) { fprintf(stderr, "\t%s\n", hmp_cmds[i]); } - response =3D hmp(hmp_cmds[i]); + response =3D hmp("%s", hmp_cmds[i]); g_free(response); } @@ -103,7 +103,7 @@ static void test_info_commands(void) if (verbose) { fprintf(stderr, "\t%s\n", info); } - resp =3D hmp(info); + resp =3D hmp("%s", info); g_free(resp); /* And move forward to the next line */ info =3D strchr(endp + 1, '\n'); --=20 2.9.4 From nobody Thu May 2 19:56:55 2024 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.zohomail.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 1500059426402174.15229805707065; Fri, 14 Jul 2017 12:10:26 -0700 (PDT) Received: from localhost ([::1]:39547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5yo-0004O5-Hb for importer@patchew.org; Fri, 14 Jul 2017 15:10:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54207) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dW5x6-0002OH-Gp for qemu-devel@nongnu.org; Fri, 14 Jul 2017 15:08:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dW5x5-00022F-HE for qemu-devel@nongnu.org; Fri, 14 Jul 2017 15:08:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59618) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dW5x5-00021x-8g for qemu-devel@nongnu.org; Fri, 14 Jul 2017 15:08:35 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 594C8F810 for ; Fri, 14 Jul 2017 19:08:34 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id D82F55D966; Fri, 14 Jul 2017 19:08:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 594C8F810 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 594C8F810 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 14:08:27 -0500 Message-Id: <20170714190827.4083-6-eblake@redhat.com> In-Reply-To: <20170714190827.4083-1-eblake@redhat.com> References: <20170714190827.4083-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 14 Jul 2017 19:08:34 +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 5/5] qtest: Document calling conventions 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: armbru@redhat.com 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" We have two flavors of vararg usage in qtest; make it clear that qmp() has different semantics than hmp(), and let the compiler enforce that hmp() is used correctly. Since qmp() only accepts a subset of printf flags (namely, those that our JSON parser understands), I figured that it is probably not worth adding a format attribute to qmp() at this time. Signed-off-by: Eric Blake --- tests/libqtest.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/libqtest.h b/tests/libqtest.h index 38bc1e9..762ed13 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -50,7 +50,8 @@ void qtest_quit(QTestState *s); /** * qtest_qmp_discard_response: * @s: #QTestState instance to operate on. - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu; only recognizes formats + * understood by json-lexer.c * * Sends a QMP message to QEMU and consumes the response. */ @@ -59,7 +60,8 @@ void qtest_qmp_discard_response(QTestState *s, const char= *fmt, ...); /** * qtest_qmp: * @s: #QTestState instance to operate on. - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu; only recognizes formats + * understood by json-lexer.c * * Sends a QMP message to QEMU and returns the response. */ @@ -134,14 +136,14 @@ QDict *qtest_qmp_eventwait_ref(QTestState *s, const c= har *event); /** * qtest_hmp: * @s: #QTestState instance to operate on. - * @fmt...: HMP command to send to QEMU + * @fmt...: HMP command to send to QEMU, passed through sprintf() * * Send HMP command to QEMU via QMP's human-monitor-command. * QMP events are discarded. * * Returns: the command's output. The caller should g_free() it. */ -char *qtest_hmp(QTestState *s, const char *fmt, ...); +char *qtest_hmp(QTestState *s, const char *fmt, ...) GCC_FMT_ATTR(2, 3); /** * qtest_hmpv: @@ -535,7 +537,8 @@ static inline void qtest_end(void) /** * qmp: - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu; only recognizes formats + * understood by json-lexer.c * * Sends a QMP message to QEMU and returns the response. */ @@ -543,7 +546,8 @@ QDict *qmp(const char *fmt, ...); /** * qmp_async: - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu; only recognizes formats + * understood by json-lexer.c * * Sends a QMP message to QEMU and leaves the response in the stream. */ @@ -551,7 +555,8 @@ void qmp_async(const char *fmt, ...); /** * qmp_discard_response: - * @fmt...: QMP message to send to qemu + * @fmt...: QMP message to send to qemu; only recognizes formats + * understood by json-lexer.c * * Sends a QMP message to QEMU and consumes the response. */ @@ -592,13 +597,13 @@ static inline QDict *qmp_eventwait_ref(const char *ev= ent) /** * hmp: - * @fmt...: HMP command to send to QEMU + * @fmt...: HMP command to send to QEMU, passed through printf() * * Send HMP command to QEMU via QMP's human-monitor-command. * * Returns: the command's output. The caller should g_free() it. */ -char *hmp(const char *fmt, ...); +char *hmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2); /** * get_irq: --=20 2.9.4