From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:58522) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgYJY-0002wn-4z for qemu-devel@nongnu.org; Thu, 06 Dec 2012 05:04:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TgYJT-0005Ce-KM for qemu-devel@nongnu.org; Thu, 06 Dec 2012 05:04:20 -0500 Message-ID: <50C06D98.9040804@redhat.com> Date: Thu, 06 Dec 2012 11:04:08 +0100 From: Kevin Wolf MIME-Version: 1.0 References: <1352101300-12060-1-git-send-email-lig.fnst@cn.fujitsu.com> In-Reply-To: <1352101300-12060-1-git-send-email-lig.fnst@cn.fujitsu.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v4] correct error message qemu-img reported List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: liguang Cc: qemu-trivial@nongnu.org, Stefan Hajnoczi , qemu-devel@nongnu.org Am 05.11.2012 08:41, schrieb liguang: > qemu-img will complain when qcow or qcow2 > size overflow for 64 bits, report the right > message in this condition. > > Signed-off-by: liguang > --- > qemu-img.c | 7 ++++++- > 1 files changed, 6 insertions(+), 1 deletions(-) > > diff --git a/qemu-img.c b/qemu-img.c > index b41e670..d9434ad 100644 > --- a/qemu-img.c > +++ b/qemu-img.c > @@ -340,7 +340,12 @@ static int img_create(int argc, char **argv) > int64_t sval; > char *end; > sval = strtosz_suffix(argv[optind++], &end, STRTOSZ_DEFSUFFIX_B); > - if (sval < 0 || *end) { > + if (sval < 0) { > + error_report("Image size must be less than 8 exabytes!"); > + ret = -1; > + goto out; > + } This is wrong, overflows are not the only way how strtosz_suffix() can fail. Before this patch: $ ./qemu-img create /tmp/foo bar qemu-img: Invalid image size specified! You may use k, M, G or T suffixes for qemu-img: kilobytes, megabytes, gigabytes and terabytes With the patch applied: $ ./qemu-img create /tmp/foo bar qemu-img: Image size must be less than 8 exabytes! Kevin > + if (*end) { > error_report("Invalid image size specified! You may use k, M, G or " > "T suffixes for "); > error_report("kilobytes, megabytes, gigabytes and terabytes."); >