Received: from [140.186.70.92] (port=33271 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PODFG-00011p-0R for qemu-devel@nongnu.org; Thu, 02 Dec 2010 12:47:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PODFA-0001n5-Bf for qemu-devel@nongnu.org; Thu, 02 Dec 2010 12:47:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48324) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PODFA-0001mt-4u for qemu-devel@nongnu.org; Thu, 02 Dec 2010 12:46:56 -0500 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.13.8/8.13.8) with ESMTP id oB2Hktih019132 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 2 Dec 2010 12:46:55 -0500 From: Jes.Sorensen@redhat.com Date: Thu, 2 Dec 2010 18:46:49 +0100 Message-Id: <1291312009-24351-4-git-send-email-Jes.Sorensen@redhat.com> In-Reply-To: <1291312009-24351-1-git-send-email-Jes.Sorensen@redhat.com> References: <1291312009-24351-1-git-send-email-Jes.Sorensen@redhat.com> Subject: [Qemu-devel] [PATCH 3/3] Fail if detecting an unknown option List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: kwolf@redhat.com Cc: qemu-devel@nongnu.org From: Jes Sorensen This patch changes qemu-img to exit if an unknown option is detected, instead of trying to continue with a set of arguments which may be incorrect. Signed-off-by: Jes Sorensen --- qemu-img.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 48 insertions(+), 0 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index d0dc445..f2e1c94 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -304,6 +304,12 @@ static int img_create(int argc, char **argv) flags = 0; for(;;) { c = getopt(argc, argv, "F:b:f:he6o:"); + /* + * Fail if we detect an unknown argument + */ + if (c == '?') { + return 1; + } if (c == -1) { break; } @@ -472,6 +478,12 @@ static int img_check(int argc, char **argv) fmt = NULL; for(;;) { c = getopt(argc, argv, "f:h"); + /* + * Fail if we detect an unknown argument + */ + if (c == '?') { + return 1; + } if (c == -1) { break; } @@ -550,6 +562,12 @@ static int img_commit(int argc, char **argv) fmt = NULL; for(;;) { c = getopt(argc, argv, "f:h"); + /* + * Fail if we detect an unknown argument + */ + if (c == '?') { + return 1; + } if (c == -1) { break; } @@ -688,6 +706,12 @@ static int img_convert(int argc, char **argv) flags = 0; for(;;) { c = getopt(argc, argv, "f:O:B:s:hce6o:"); + /* + * Fail if we detect an unknown argument + */ + if (c == '?') { + return 1; + } if (c == -1) { break; } @@ -1094,6 +1118,12 @@ static int img_info(int argc, char **argv) fmt = NULL; for(;;) { c = getopt(argc, argv, "f:h"); + /* + * Fail if we detect an unknown argument + */ + if (c == '?') { + return 1; + } if (c == -1) { break; } @@ -1171,6 +1201,12 @@ static int img_snapshot(int argc, char **argv) /* Parse commandline parameters */ for(;;) { c = getopt(argc, argv, "la:c:d:h"); + /* + * Fail if we detect an unknown argument + */ + if (c == '?') { + return 1; + } if (c == -1) { break; } @@ -1286,6 +1322,12 @@ static int img_rebase(int argc, char **argv) for(;;) { c = getopt(argc, argv, "uhf:F:b:"); + /* + * Fail if we detect an unknown argument + */ + if (c == '?') { + return 1; + } if (c == -1) { break; } @@ -1500,6 +1542,12 @@ static int img_resize(int argc, char **argv) fmt = NULL; for(;;) { c = getopt(argc, argv, "f:h"); + /* + * Fail if we detect an unknown argument + */ + if (c == '?') { + return 1; + } if (c == -1) { break; } -- 1.7.3.2