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