diff mbox

[2/2] qemu-img:report size overflow error message

Message ID 1355458116-5692-2-git-send-email-lig.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

liguang Dec. 14, 2012, 4:08 a.m. UTC
qemu-img will complain when qcow or qcow2
size overflow for 64 bits, report the right
message in this condition.

before change:
qemu-img: Invalid image size specified! You may use k, M, G or T suffixes for
qemu-img: kilobytes, megabytes, gigabytes and terabytes.

after change:
qemu-img: Image size must be less than 8 exabytes!

Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
---
 qemu-img.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

Comments

Markus Armbruster Dec. 14, 2012, 12:19 p.m. UTC | #1
liguang <lig.fnst@cn.fujitsu.com> writes:

> qemu-img will complain when qcow or qcow2
> size overflow for 64 bits, report the right
> message in this condition.
>
> before change:
> qemu-img: Invalid image size specified! You may use k, M, G or T suffixes for
> qemu-img: kilobytes, megabytes, gigabytes and terabytes.
>
> after change:
> qemu-img: Image size must be less than 8 exabytes!
>
> Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
> ---
>  qemu-img.c |    7 ++++++-
>  1 files changed, 6 insertions(+), 1 deletions(-)
>
> diff --git a/qemu-img.c b/qemu-img.c
> index e29e01b..1c3af67 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -346,13 +346,18 @@ 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 == EINVAL || *end) {
>              error_report("Invalid image size specified! You may use k, M, G or "
>                    "T suffixes for ");
>              error_report("kilobytes, megabytes, gigabytes and terabytes.");
>              ret = -1;
>              goto out;
>          }
> +        if (sval == ERANGE) {
> +            error_report("Image size must be less than 8 exabytes!");
> +            ret = -1;
> +            goto out;
> +        }
>          img_size = (uint64_t)sval;
>      }

If strtosz_suffix() ever acquires additional error codes, this caller
will fail to detect the failure.  Try something like

        if (sval < 0 || *end) {
            if (sval == -ERANGE) {
                error_report("Image size must be less than 8 exabytes!");
            } else {
                error_report("Invalid image size specified!"
                      " You may use k, M, G or T suffixes for");
                error_report("kilobytes, megabytes, gigabytes and terabytes.");
            }
            ret = -1;
            goto out;
        }

To be pedantically correct, "8 exabytes" should be "8 Exbibytes" or "8
EiB".
liguang Dec. 17, 2012, 12:34 a.m. UTC | #2
在 2012-12-14五的 13:19 +0100,Markus Armbruster写道:
> liguang <lig.fnst@cn.fujitsu.com> writes:
> 
> > qemu-img will complain when qcow or qcow2
> > size overflow for 64 bits, report the right
> > message in this condition.
> >
> > before change:
> > qemu-img: Invalid image size specified! You may use k, M, G or T suffixes for
> > qemu-img: kilobytes, megabytes, gigabytes and terabytes.
> >
> > after change:
> > qemu-img: Image size must be less than 8 exabytes!
> >
> > Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
> > ---
> >  qemu-img.c |    7 ++++++-
> >  1 files changed, 6 insertions(+), 1 deletions(-)
> >
> > diff --git a/qemu-img.c b/qemu-img.c
> > index e29e01b..1c3af67 100644
> > --- a/qemu-img.c
> > +++ b/qemu-img.c
> > @@ -346,13 +346,18 @@ 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 == EINVAL || *end) {
> >              error_report("Invalid image size specified! You may use k, M, G or "
> >                    "T suffixes for ");
> >              error_report("kilobytes, megabytes, gigabytes and terabytes.");
> >              ret = -1;
> >              goto out;
> >          }
> > +        if (sval == ERANGE) {
> > +            error_report("Image size must be less than 8 exabytes!");
> > +            ret = -1;
> > +            goto out;
> > +        }
> >          img_size = (uint64_t)sval;
> >      }
> 
> If strtosz_suffix() ever acquires additional error codes, this caller
> will fail to detect the failure.  Try something like
> 
>         if (sval < 0 || *end) {
>             if (sval == -ERANGE) {
>                 error_report("Image size must be less than 8 exabytes!");
>             } else {
>                 error_report("Invalid image size specified!"
>                       " You may use k, M, G or T suffixes for");
>                 error_report("kilobytes, megabytes, gigabytes and terabytes.");
>             }
>             ret = -1;
>             goto out;
>         }
> 
> To be pedantically correct, "8 exabytes" should be "8 Exbibytes" or "8
> EiB".

yes, it's better.
Thanks!
diff mbox

Patch

diff --git a/qemu-img.c b/qemu-img.c
index e29e01b..1c3af67 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -346,13 +346,18 @@  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 == EINVAL || *end) {
             error_report("Invalid image size specified! You may use k, M, G or "
                   "T suffixes for ");
             error_report("kilobytes, megabytes, gigabytes and terabytes.");
             ret = -1;
             goto out;
         }
+        if (sval == ERANGE) {
+            error_report("Image size must be less than 8 exabytes!");
+            ret = -1;
+            goto out;
+        }
         img_size = (uint64_t)sval;
     }