From nobody Mon Feb 9 09:52:31 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 1488545050188295.247030177405; Fri, 3 Mar 2017 04:44:10 -0800 (PST) Received: from localhost ([::1]:57545 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjmZ5-0008Mj-7j for importer@patchew.org; Fri, 03 Mar 2017 07:44:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42545) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjmOI-0007wv-Lg for qemu-devel@nongnu.org; Fri, 03 Mar 2017 07:33:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cjmOF-00081i-Vo for qemu-devel@nongnu.org; Fri, 03 Mar 2017 07:32:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48158) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cjmOF-0007zz-GI for qemu-devel@nongnu.org; Fri, 03 Mar 2017 07:32:55 -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 83BF92EF16A for ; Fri, 3 Mar 2017 12:32:55 +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 1D79C2D655; Fri, 3 Mar 2017 12:32:55 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2AD5E1138610; Fri, 3 Mar 2017 13:32:49 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 3 Mar 2017 13:32:36 +0100 Message-Id: <1488544368-30622-17-git-send-email-armbru@redhat.com> In-Reply-To: <1488544368-30622-1-git-send-email-armbru@redhat.com> References: <1488544368-30622-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.29]); Fri, 03 Mar 2017 12:32:55 +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 v4 16/28] 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 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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