Patchwork [v3] correct error message qemu-img reported

login
register
mail settings
Submitter liguang
Date Nov. 2, 2012, 5:11 a.m.
Message ID <1351833082-26633-1-git-send-email-lig.fnst@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/196484/
State New
Headers show

Comments

liguang - Nov. 2, 2012, 5:11 a.m.
qemu-img will complain when qcow or qcow2
size overflow for 64 bits, report the right
message in this condition.

Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
---
 qemu-img.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
Stefan Hajnoczi - Nov. 2, 2012, 7:16 a.m.
On Fri, Nov 2, 2012 at 6:11 AM, liguang <lig.fnst@cn.fujitsu.com> wrote:
> diff --git a/qemu-img.c b/qemu-img.c
> index b41e670..d4ea800 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -337,10 +337,15 @@ static int img_create(int argc, char **argv)
>
>      /* Get image size, if specified */
>      if (optind < argc) {
> -        int64_t sval;
> +        int64_t sval = 0;

sval is assigned below so there is no need for this change.

>          char *end;
>          sval = strtosz_suffix(argv[optind++], &end, STRTOSZ_DEFSUFFIX_B);
> -        if (sval < 0 || *end) {
> +        if (sval < 0) {
> +            error_report("image size is too large!");

I suggest being specific about the upper limit so the user knows which
values are valid:
"Image size must be less than 8 exabytes!"

Stefan
liguang - Nov. 5, 2012, 7:40 a.m.
在 2012-11-02五的 08:16 +0100,Stefan Hajnoczi写道:
> On Fri, Nov 2, 2012 at 6:11 AM, liguang <lig.fnst@cn.fujitsu.com> wrote:
> > diff --git a/qemu-img.c b/qemu-img.c
> > index b41e670..d4ea800 100644
> > --- a/qemu-img.c
> > +++ b/qemu-img.c
> > @@ -337,10 +337,15 @@ static int img_create(int argc, char **argv)
> >
> >      /* Get image size, if specified */
> >      if (optind < argc) {
> > -        int64_t sval;
> > +        int64_t sval = 0;
> 
> sval is assigned below so there is no need for this change.
> 
> >          char *end;
> >          sval = strtosz_suffix(argv[optind++], &end, STRTOSZ_DEFSUFFIX_B);
> > -        if (sval < 0 || *end) {
> > +        if (sval < 0) {
> > +            error_report("image size is too large!");
> 
> I suggest being specific about the upper limit so the user knows which
> values are valid:
> "Image size must be less than 8 exabytes!"
> 
> Stefan
> 

OK, will fix.

Patch

diff --git a/qemu-img.c b/qemu-img.c
index b41e670..d4ea800 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -337,10 +337,15 @@  static int img_create(int argc, char **argv)
 
     /* Get image size, if specified */
     if (optind < argc) {
-        int64_t sval;
+        int64_t sval = 0;
         char *end;
         sval = strtosz_suffix(argv[optind++], &end, STRTOSZ_DEFSUFFIX_B);
-        if (sval < 0 || *end) {
+        if (sval < 0) {
+            error_report("image size is too large!");
+            ret = -1;
+            goto out;
+        }
+        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.");