Skip to contentSkip to conversation

correct error message qemu-img reported

PATCH Superseded liguang 2 participants 3 messages Nov 2, 2012 – Nov 5, 2012

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

liguang

author
#0 lore raw

PATCH v3 1/1 correct error message qemu-img reported

qemu-img will complain when qcow or qcow2
size overflow for 64 bits, report the right
message in this condition.

---
 qemu-img.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
qemu-img.c +7 -2
index b41e670..d4ea800 100644
@@ -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.");
Signature · 1 line
1.7.1
#1 lore raw

qemu-img.c static int img_create(int argc, char **argv) · line 340

Quoted 10 lines · liguang
qemu-img.c +1 -1
index b41e670..d4ea800 100644
@@ -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.

qemu-img.c static int img_create(int argc, char **argv) · line 344

Quoted 5 lines
qemu-img.c +2 -1
         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

author
#2 lore raw
Quoted 20 lines · 在 2012-11-02五的 08:16 +0100,Stefan Hajnoczi写道:

qemu-img.c static int img_create(int argc, char **argv) · line 340

Quoted 10 lines · liguang
qemu-img.c +1 -1
index b41e670..d4ea800 100644
@@ -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.

qemu-img.c static int img_create(int argc, char **argv) · line 344

Quoted 5 lines
qemu-img.c +2 -1
         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!");
Quoted 6 lines

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.

Signature · 2 lines
liguang    [email protected]
FNST linux kernel team