From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50573) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V6J9c-0003VL-BO for qemu-devel@nongnu.org; Mon, 05 Aug 2013 07:40:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V6J9W-0001Ng-94 for qemu-devel@nongnu.org; Mon, 05 Aug 2013 07:40:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57383) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V6J9V-0001NZ-Uk for qemu-devel@nongnu.org; Mon, 05 Aug 2013 07:40:42 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r75Beeo2010877 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 5 Aug 2013 07:40:41 -0400 Message-ID: <51FF8FCC.1040609@redhat.com> Date: Mon, 05 Aug 2013 13:43:08 +0200 From: Laszlo Ersek MIME-Version: 1.0 References: <1375693060-16407-1-git-send-email-kwolf@redhat.com> In-Reply-To: <1375693060-16407-1-git-send-email-kwolf@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH for-1.6] qemu-img: Error out for excess arguments List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: qemu-devel@nongnu.org, stefanha@redhat.com On 08/05/13 10:57, Kevin Wolf wrote: > Don't silently ignore excess arguments at the end of the command line, > but error out instead. This can catch typos like 'resize test.img + 1G', > which doesn't increase the image size by 1G as intended, but truncates > the image to 1G. Even for less dangerous commands, the old behaviour is > confusing. > > Signed-off-by: Kevin Wolf > --- > qemu-img.c | 17 ++++++++++------- > 1 file changed, 10 insertions(+), 7 deletions(-) > > diff --git a/qemu-img.c b/qemu-img.c > index c55ca5c..dece1b3 100644 > --- a/qemu-img.c > +++ b/qemu-img.c > @@ -396,6 +396,9 @@ static int img_create(int argc, char **argv) > } > img_size = (uint64_t)sval; > } > + if (optind != argc) { > + help(); > + } > > if (options && is_help_option(options)) { > return print_block_option_help(filename, fmt); > @@ -573,7 +576,7 @@ static int img_check(int argc, char **argv) > break; > } > } > - if (optind >= argc) { > + if (optind != argc - 1) { > help(); > } > filename = argv[optind++]; > @@ -684,7 +687,7 @@ static int img_commit(int argc, char **argv) > break; > } > } > - if (optind >= argc) { > + if (optind != argc - 1) { > help(); > } > filename = argv[optind++]; > @@ -930,7 +933,7 @@ static int img_compare(int argc, char **argv) > } > > > - if (optind > argc - 2) { > + if (optind != argc - 2) { > help(); > } > filename1 = argv[optind++]; > @@ -1741,7 +1744,7 @@ static int img_info(int argc, char **argv) > break; > } > } > - if (optind >= argc) { > + if (optind != argc - 1) { > help(); > } > filename = argv[optind++]; > @@ -1842,7 +1845,7 @@ static int img_snapshot(int argc, char **argv) > } > } > > - if (optind >= argc) { > + if (optind != argc - 1) { > help(); > } > filename = argv[optind++]; > @@ -1953,7 +1956,7 @@ static int img_rebase(int argc, char **argv) > progress = 0; > } > > - if ((optind >= argc) || (!unsafe && !out_baseimg)) { > + if ((optind != argc - 1) || (!unsafe && !out_baseimg)) { > help(); > } > filename = argv[optind++]; > @@ -2232,7 +2235,7 @@ static int img_resize(int argc, char **argv) > break; > } > } > - if (optind >= argc) { > + if (optind != argc - 1) { > help(); > } > filename = argv[optind++]; > Reviewed-by: Laszlo Ersek