From nobody Mon Feb 9 08:57:02 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 1487881163374101.85958007440809; Thu, 23 Feb 2017 12:19:23 -0800 (PST) Received: from localhost ([::1]:60814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgzrG-0002q5-7o for importer@patchew.org; Thu, 23 Feb 2017 15:19:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39930) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgzSy-00023Q-Hp for qemu-devel@nongnu.org; Thu, 23 Feb 2017 14:54:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgzSx-0000wS-EK for qemu-devel@nongnu.org; Thu, 23 Feb 2017 14:54:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35920) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgzSq-0000pQ-U6; Thu, 23 Feb 2017 14:54:09 -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 EB82C7FB60; Thu, 23 Feb 2017 19:54:08 +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 89B23B7D3E; Thu, 23 Feb 2017 19:54:08 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id BABFD113861C; Thu, 23 Feb 2017 20:54:02 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 23 Feb 2017 20:53:58 +0100 Message-Id: <1487879642-16139-21-git-send-email-armbru@redhat.com> In-Reply-To: <1487879642-16139-1-git-send-email-armbru@redhat.com> References: <1487879642-16139-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.25]); Thu, 23 Feb 2017 19:54:08 +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] [PULL 20/24] qemu-img: Wrap cvtnum() around qemu_strtosz() 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: Kevin Wolf , qemu-block@nongnu.org, Max Reitz 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" Cc: Kevin Wolf Cc: Max Reitz Cc: qemu-block@nongnu.org Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <1487708048-2131-21-git-send-email-armbru@redhat.com> --- qemu-img.c | 58 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index f1c641c..4062917 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -368,6 +368,19 @@ static int add_old_style_options(const char *fmt, Qemu= Opts *opts, return 0; } =20 +static int64_t cvtnum(const char *s) +{ + char *end; + int64_t ret; + + ret =3D qemu_strtosz(s, &end); + if (*end !=3D '\0') { + /* Detritus at the end of the string */ + return -EINVAL; + } + return ret; +} + static int img_create(int argc, char **argv) { int c; @@ -461,9 +474,9 @@ static int img_create(int argc, char **argv) /* Get image size, if specified */ if (optind < argc) { int64_t sval; - char *end; - sval =3D qemu_strtosz(argv[optind++], &end); - if (sval < 0 || *end) { + + sval =3D cvtnum(argv[optind++]); + if (sval < 0) { if (sval =3D=3D -ERANGE) { error_report("Image size must be less than 8 EiB!"); } else { @@ -1863,9 +1876,9 @@ static int img_convert(int argc, char **argv) case 'S': { int64_t sval; - char *end; - sval =3D qemu_strtosz(optarg, &end); - if (sval < 0 || *end) { + + sval =3D cvtnum(optarg); + if (sval < 0) { error_report("Invalid minimum zero buffer size for sparse = output specified"); ret =3D -1; goto fail_getopt; @@ -3650,10 +3663,8 @@ static int img_bench(int argc, char **argv) break; case 'o': { - char *end; - errno =3D 0; - offset =3D qemu_strtosz(optarg, &end); - if (offset < 0|| *end) { + offset =3D cvtnum(optarg); + if (offset < 0) { error_report("Invalid offset specified"); return 1; } @@ -3666,10 +3677,9 @@ static int img_bench(int argc, char **argv) case 's': { int64_t sval; - char *end; =20 - sval =3D qemu_strtosz(optarg, &end); - if (sval < 0 || sval > INT_MAX || *end) { + sval =3D cvtnum(optarg); + if (sval < 0 || sval > INT_MAX) { error_report("Invalid buffer size specified"); return 1; } @@ -3680,10 +3690,9 @@ static int img_bench(int argc, char **argv) case 'S': { int64_t sval; - char *end; =20 - sval =3D qemu_strtosz(optarg, &end); - if (sval < 0 || sval > INT_MAX || *end) { + sval =3D cvtnum(optarg); + if (sval < 0 || sval > INT_MAX) { error_report("Invalid step size specified"); return 1; } @@ -3842,12 +3851,11 @@ static int img_dd_bs(const char *arg, struct DdIo *in, struct DdIo *out, struct DdInfo *dd) { - char *end; int64_t res; =20 - res =3D qemu_strtosz(arg, &end); + res =3D cvtnum(arg); =20 - if (res <=3D 0 || res > INT_MAX || *end) { + if (res <=3D 0 || res > INT_MAX) { error_report("invalid number: '%s'", arg); return 1; } @@ -3860,11 +3868,9 @@ static int img_dd_count(const char *arg, struct DdIo *in, struct DdIo *out, struct DdInfo *dd) { - char *end; + dd->count =3D cvtnum(arg); =20 - dd->count =3D qemu_strtosz(arg, &end); - - if (dd->count < 0 || *end) { + if (dd->count < 0) { error_report("invalid number: '%s'", arg); return 1; } @@ -3894,11 +3900,9 @@ static int img_dd_skip(const char *arg, struct DdIo *in, struct DdIo *out, struct DdInfo *dd) { - char *end; + in->offset =3D cvtnum(arg); =20 - in->offset =3D qemu_strtosz(arg, &end); - - if (in->offset < 0 || *end) { + if (in->offset < 0) { error_report("invalid number: '%s'", arg); return 1; } --=20 2.7.4