958e1b
From ff6247a010ae1c37e400bbdd232df40ddcdf1bfc Mon Sep 17 00:00:00 2001
958e1b
From: Amos Kong <akong@redhat.com>
958e1b
Date: Mon, 4 Aug 2014 03:33:38 +0200
958e1b
Subject: [PATCH 4/4] qapi: treat all negative return of strtosz_suffix() as error
958e1b
958e1b
Message-id: <1407123218-15659-1-git-send-email-akong@redhat.com>
958e1b
Patchwork-id: 60413
958e1b
O-Subject: [RHEL-7.1 qemu-kvm PATCH] qapi: treat all negative return of strtosz_suffix() as error
958e1b
Bugzilla: 1074403
958e1b
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
958e1b
RH-Acked-by: Fam Zheng <famz@redhat.com>
958e1b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
958e1b
958e1b
Bug: 1074403
958e1b
Brew: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=7780802
958e1b
Test: tested by myself
958e1b
958e1b
strtosz_suffix() might return negative error, this patch fixes
958e1b
the error handling.
958e1b
958e1b
This patch also changes to handle error in the if statement
958e1b
rather than handle success specially, this will make this use
958e1b
of strtosz_suffix consistent with all other uses.
958e1b
958e1b
Signed-off-by: Amos Kong <akong@redhat.com>
958e1b
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
958e1b
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
958e1b
(cherry picked from commit cb45de6798956975c4b13a6233f7a00d2239b61a)
958e1b
---
958e1b
 qapi/opts-visitor.c |   11 ++++++-----
958e1b
 1 files changed, 6 insertions(+), 5 deletions(-)
958e1b
958e1b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
---
958e1b
 qapi/opts-visitor.c |   11 ++++++-----
958e1b
 1 files changed, 6 insertions(+), 5 deletions(-)
958e1b
958e1b
diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
958e1b
index 174bd8b..bbb99e9 100644
958e1b
--- a/qapi/opts-visitor.c
958e1b
+++ b/qapi/opts-visitor.c
958e1b
@@ -348,13 +348,14 @@ opts_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp)
958e1b
 
958e1b
     val = strtosz_suffix(opt->str ? opt->str : "", &endptr,
958e1b
                          STRTOSZ_DEFSUFFIX_B);
958e1b
-    if (val != -1 && *endptr == '\0') {
958e1b
-        *obj = val;
958e1b
-        processed(ov, name);
958e1b
+    if (val < 0 || *endptr) {
958e1b
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, opt->name,
958e1b
+                  "a size value representible as a non-negative int64");
958e1b
         return;
958e1b
     }
958e1b
-    error_set(errp, QERR_INVALID_PARAMETER_VALUE, opt->name,
958e1b
-              "a size value representible as a non-negative int64");
958e1b
+
958e1b
+    *obj = val;
958e1b
+    processed(ov, name);
958e1b
 }
958e1b
 
958e1b
 
958e1b
-- 
958e1b
1.7.1
958e1b