* [Qemu-devel] [PATCH for-1.6] qemu-img: Error out for excess arguments
@ 2013-08-05 8:57 Kevin Wolf
2013-08-05 11:43 ` Laszlo Ersek
2013-08-06 8:09 ` Stefan Hajnoczi
0 siblings, 2 replies; 3+ messages in thread
From: Kevin Wolf @ 2013-08-05 8:57 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
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 <kwolf@redhat.com>
---
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++];
--
1.8.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH for-1.6] qemu-img: Error out for excess arguments
2013-08-05 8:57 [Qemu-devel] [PATCH for-1.6] qemu-img: Error out for excess arguments Kevin Wolf
@ 2013-08-05 11:43 ` Laszlo Ersek
2013-08-06 8:09 ` Stefan Hajnoczi
1 sibling, 0 replies; 3+ messages in thread
From: Laszlo Ersek @ 2013-08-05 11:43 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-devel, stefanha
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 <kwolf@redhat.com>
> ---
> 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 <lersek@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH for-1.6] qemu-img: Error out for excess arguments
2013-08-05 8:57 [Qemu-devel] [PATCH for-1.6] qemu-img: Error out for excess arguments Kevin Wolf
2013-08-05 11:43 ` Laszlo Ersek
@ 2013-08-06 8:09 ` Stefan Hajnoczi
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2013-08-06 8:09 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-devel
On Mon, Aug 05, 2013 at 10:57:40AM +0200, 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 <kwolf@redhat.com>
> ---
> qemu-img.c | 17 ++++++++++-------
> 1 file changed, 10 insertions(+), 7 deletions(-)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-08-06 8:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-05 8:57 [Qemu-devel] [PATCH for-1.6] qemu-img: Error out for excess arguments Kevin Wolf
2013-08-05 11:43 ` Laszlo Ersek
2013-08-06 8:09 ` Stefan Hajnoczi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).