From nobody Wed Apr 24 08:16:16 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.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 1486744521613251.49727027478264; Fri, 10 Feb 2017 08:35:21 -0800 (PST) Received: from localhost ([::1]:44733 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ccEAJ-0002ky-My for importer@patchew.org; Fri, 10 Feb 2017 11:35:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ccE95-0002F0-Sj for qemu-devel@nongnu.org; Fri, 10 Feb 2017 11:34:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ccE94-0005hW-Pt for qemu-devel@nongnu.org; Fri, 10 Feb 2017 11:34:03 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:48468) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ccE94-0005hE-II for qemu-devel@nongnu.org; Fri, 10 Feb 2017 11:34:02 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1ccE3e-0007Wh-Rf; Fri, 10 Feb 2017 16:28:26 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 10 Feb 2017 16:28:23 +0000 Message-Id: <1486744104-15590-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486744104-15590-1-git-send-email-peter.maydell@linaro.org> References: <1486744104-15590-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH 1/2] qemu-img: Use qemu_strtoul() rather than raw strtoul() 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 , Max Reitz , qemu-block@nongnu.org, patches@linaro.org 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" Some of the argument parsing in qemu-img uses strtoul() to parse integer arguments. This is tricky to get correct and in fact the code does not get it right, because it assigns the result of strtoul() to an 'int' variable and then tries to check for > INT_MAX. Coverity correctly complains that the comparison is always false. Rewrite to use qemu_strtoul(), which has a saner convention for reporting conversion failures. (Fixes CID 1356421, CID 1356422, CID 1356423.) Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- qemu-img.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 74e3362..aa71588 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3621,24 +3621,24 @@ static int img_bench(int argc, char **argv) break; case 'c': { - char *end; - errno =3D 0; - count =3D strtoul(optarg, &end, 0); - if (errno || *end || count > INT_MAX) { + unsigned long res; + + if (qemu_strtoul(optarg, NULL, 0, &res) < 0 || res > INT_MAX) { error_report("Invalid request count specified"); return 1; } + count =3D res; break; } case 'd': { - char *end; - errno =3D 0; - depth =3D strtoul(optarg, &end, 0); - if (errno || *end || depth > INT_MAX) { + unsigned long res; + + if (qemu_strtoul(optarg, NULL, 0, &res) < 0 || res > INT_MAX) { error_report("Invalid queue depth specified"); return 1; } + depth =3D res; break; } case 'f': @@ -3705,24 +3705,24 @@ static int img_bench(int argc, char **argv) break; case OPTION_PATTERN: { - char *end; - errno =3D 0; - pattern =3D strtoul(optarg, &end, 0); - if (errno || *end || pattern > 0xff) { + unsigned long res; + + if (qemu_strtoul(optarg, NULL, 0, &res) < 0 || res > 0xff) { error_report("Invalid pattern byte specified"); return 1; } + pattern =3D res; break; } case OPTION_FLUSH_INTERVAL: { - char *end; - errno =3D 0; - flush_interval =3D strtoul(optarg, &end, 0); - if (errno || *end || flush_interval > INT_MAX) { + unsigned long res; + + if (qemu_strtoul(optarg, NULL, 0, &res) < 0 || res > INT_MAX) { error_report("Invalid flush interval specified"); return 1; } + flush_interval =3D res; break; } case OPTION_NO_DRAIN: --=20 2.7.4 From nobody Wed Apr 24 08:16:16 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.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 1486744193160899.2268387276908; Fri, 10 Feb 2017 08:29:53 -0800 (PST) Received: from localhost ([::1]:44706 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ccE4y-0008Ry-3R for importer@patchew.org; Fri, 10 Feb 2017 11:29:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50138) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ccE3j-0007ky-Ph for qemu-devel@nongnu.org; Fri, 10 Feb 2017 11:28:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ccE3i-0004Q6-R6 for qemu-devel@nongnu.org; Fri, 10 Feb 2017 11:28:31 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:48463) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ccE3i-0004Q0-Hp for qemu-devel@nongnu.org; Fri, 10 Feb 2017 11:28:30 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1ccE3f-0007Ws-AE; Fri, 10 Feb 2017 16:28:27 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 10 Feb 2017 16:28:24 +0000 Message-Id: <1486744104-15590-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486744104-15590-1-git-send-email-peter.maydell@linaro.org> References: <1486744104-15590-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH 2/2] qemu-img: Avoid setting ret to unused value in img_convert() 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 , Max Reitz , qemu-block@nongnu.org, patches@linaro.org 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" Coverity points out that we assign the return value from bdrv_snapshot_load_tmp() to 'ret' in img_convert(), but then never use that variable. (We check for failure by looking at local_err instead.) Drop the unused assignment, bringing the call into line with the following call to bdrv_snapshot_laod_tmp_by_id_or_name(). (Fixes CID 1247240.) Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- qemu-img.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index aa71588..9227d3a 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1966,10 +1966,10 @@ static int img_convert(int argc, char **argv) } =20 if (sn_opts) { - ret =3D bdrv_snapshot_load_tmp(bs[0], - qemu_opt_get(sn_opts, SNAPSHOT_OPT_ID= ), - qemu_opt_get(sn_opts, SNAPSHOT_OPT_NA= ME), - &local_err); + bdrv_snapshot_load_tmp(bs[0], + qemu_opt_get(sn_opts, SNAPSHOT_OPT_ID), + qemu_opt_get(sn_opts, SNAPSHOT_OPT_NAME), + &local_err); } else if (snapshot_name !=3D NULL) { if (bs_n > 1) { error_report("No support for concatenating multiple snapshot"); --=20 2.7.4