summaryrefslogtreecommitdiff
path: root/qemu-img.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2013-08-05 10:53:04 +0200
committerKevin Wolf <kwolf@redhat.com>2013-08-06 10:41:56 +0200
commitfc11eb26cee7e3621645dd40cd9de944201f590b (patch)
tree6068a1a2717cc97e63d07c9ea22be60c97cbae61 /qemu-img.c
parent79761c6681f0d1cc1c027116fcb4382d41ed3ece (diff)
downloadqemu-fc11eb26cee7e3621645dd40cd9de944201f590b.tar.gz
qemu-img: Error out for excess arguments
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> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'qemu-img.c')
-rw-r--r--qemu-img.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/qemu-img.c b/qemu-img.c
index c55ca5c557..dece1b3a3a 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++];