From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:48609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RSlzY-0006E7-PK for qemu-devel@nongnu.org; Tue, 22 Nov 2011 03:46:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RSlzX-00008B-N9 for qemu-devel@nongnu.org; Tue, 22 Nov 2011 03:46:12 -0500 Received: from oxygen.pond.sub.org ([78.46.104.156]:53678) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RSlzX-00007z-Da for qemu-devel@nongnu.org; Tue, 22 Nov 2011 03:46:11 -0500 Received: from blackfin.pond.sub.org (p5B32D94C.dip.t-dialin.net [91.50.217.76]) by oxygen.pond.sub.org (Postfix) with ESMTPA id 3D2E8A4114 for ; Tue, 22 Nov 2011 09:46:08 +0100 (CET) From: Markus Armbruster Date: Tue, 22 Nov 2011 09:46:05 +0100 Message-Id: <1321951566-11667-6-git-send-email-armbru@redhat.com> In-Reply-To: <1321951566-11667-1-git-send-email-armbru@redhat.com> References: <1321951566-11667-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PATCH 5/6] qemu-img: Tighten parsing of size arguments List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Jes.Sorensen@redhat.com strtosz_suffix() fails unless the size is followed by 0, whitespace or ','. Useless here, because we need to fail for any junk following the size, even if it starts with whitespace or ','. Check manually. Things like "qemu-img create xxx 1024," and "qemu-img convert -S '1024 junk'" are now caught. Signed-off-by: Markus Armbruster --- qemu-img.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 86127f0..8bdae66 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -332,8 +332,9 @@ static int img_create(int argc, char **argv) /* Get image size, if specified */ if (optind < argc) { int64_t sval; - sval = strtosz_suffix(argv[optind++], NULL, STRTOSZ_DEFSUFFIX_B); - if (sval < 0) { + char *end; + sval = strtosz_suffix(argv[optind++], &end, STRTOSZ_DEFSUFFIX_B); + if (sval < 0 || *end) { error_report("Invalid image size specified! You may use k, M, G or " "T suffixes for "); error_report("kilobytes, megabytes, gigabytes and terabytes."); @@ -710,8 +711,9 @@ static int img_convert(int argc, char **argv) case 'S': { int64_t sval; - sval = strtosz_suffix(optarg, NULL, STRTOSZ_DEFSUFFIX_B); - if (sval < 0) { + char *end; + sval = strtosz_suffix(optarg, &end, STRTOSZ_DEFSUFFIX_B); + if (sval < 0 || *end) { error_report("Invalid minimum zero buffer size for sparse output specified"); return 1; } -- 1.7.6.4