From nobody Mon Feb 9 19:53:29 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 1488304430437860.049846022333; Tue, 28 Feb 2017 09:53:50 -0800 (PST) Received: from localhost ([::1]:35985 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cily8-0006w0-7E for importer@patchew.org; Tue, 28 Feb 2017 12:53:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49996) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cilkG-0003eO-PZ for qemu-devel@nongnu.org; Tue, 28 Feb 2017 12:39:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cilkD-0005R1-E0 for qemu-devel@nongnu.org; Tue, 28 Feb 2017 12:39:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48354) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cilkD-0005Q9-4l for qemu-devel@nongnu.org; Tue, 28 Feb 2017 12:39:25 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4A975C05681A for ; Tue, 28 Feb 2017 17:39:25 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1SHdN5A023045 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 28 Feb 2017 12:39:24 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 4210A113860A; Tue, 28 Feb 2017 18:39:20 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 28 Feb 2017 18:39:08 +0100 Message-Id: <1488303560-18803-15-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.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 28 Feb 2017 17:39:25 +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 14/26] qapi: Make string input and opts visitor require non-null 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: , 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 string input visitor tries to cope with null input. Null input isn't used anywhere, and isn't covered by tests. Unsurprisingly, it doesn't fully work: start_list() crashes because it passes the input via parse_str() to strtoll() unchecked. Make string_input_visitor_new() assert its argument isn't null, and drop the code trying to deal with null input. The opts visitor crashes when you try to actually visit something with null input. Make opts_visitor_new() assert its argument isn't null, mostly for clarity. qobject_input_visitor_new() already asserts its argument isn't null. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- qapi/opts-visitor.c | 1 + qapi/string-input-visitor.c | 54 ++++++++++++++---------------------------= ---- 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index a0a7c0e..c50dc4b 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -528,6 +528,7 @@ opts_visitor_new(const QemuOpts *opts) { OptsVisitor *ov; =20 + assert(opts); ov =3D g_malloc0(sizeof *ov); =20 ov->visitor.type =3D VISITOR_INPUT; diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c index 1a855c5..f126cd9 100644 --- a/qapi/string-input-visitor.c +++ b/qapi/string-input-visitor.c @@ -182,12 +182,6 @@ static void parse_type_int64(Visitor *v, const char *n= ame, int64_t *obj, { StringInputVisitor *siv =3D to_siv(v); =20 - if (!siv->string) { - error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", - "integer"); - return; - } - if (parse_str(siv, name, errp) < 0) { return; } @@ -242,13 +236,7 @@ static void parse_type_size(Visitor *v, const char *na= me, uint64_t *obj, Error *err =3D NULL; uint64_t val; =20 - if (siv->string) { - parse_option_size(name, siv->string, &val, &err); - } else { - error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", - "size"); - return; - } + parse_option_size(name, siv->string, &val, &err); if (err) { error_propagate(errp, err); return; @@ -262,19 +250,17 @@ static void parse_type_bool(Visitor *v, const char *n= ame, bool *obj, { StringInputVisitor *siv =3D to_siv(v); =20 - if (siv->string) { - if (!strcasecmp(siv->string, "on") || - !strcasecmp(siv->string, "yes") || - !strcasecmp(siv->string, "true")) { - *obj =3D true; - return; - } - if (!strcasecmp(siv->string, "off") || - !strcasecmp(siv->string, "no") || - !strcasecmp(siv->string, "false")) { - *obj =3D false; - return; - } + if (!strcasecmp(siv->string, "on") || + !strcasecmp(siv->string, "yes") || + !strcasecmp(siv->string, "true")) { + *obj =3D true; + return; + } + if (!strcasecmp(siv->string, "off") || + !strcasecmp(siv->string, "no") || + !strcasecmp(siv->string, "false")) { + *obj =3D false; + return; } =20 error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", @@ -285,13 +271,8 @@ static void parse_type_str(Visitor *v, const char *nam= e, char **obj, Error **errp) { StringInputVisitor *siv =3D to_siv(v); - if (siv->string) { - *obj =3D g_strdup(siv->string); - } else { - *obj =3D NULL; - error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", - "string"); - } + + *obj =3D g_strdup(siv->string); } =20 static void parse_type_number(Visitor *v, const char *name, double *obj, @@ -302,10 +283,8 @@ static void parse_type_number(Visitor *v, const char *= name, double *obj, double val; =20 errno =3D 0; - if (siv->string) { - val =3D strtod(siv->string, &endp); - } - if (!siv->string || errno || endp =3D=3D siv->string || *endp) { + val =3D strtod(siv->string, &endp); + if (errno || endp =3D=3D siv->string || *endp) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", "number"); return; @@ -327,6 +306,7 @@ Visitor *string_input_visitor_new(const char *str) { StringInputVisitor *v; =20 + assert(str); v =3D g_malloc0(sizeof(*v)); =20 v->visitor.type =3D VISITOR_INPUT; --=20 2.7.4