[PATCH] virsh: print error in case of cellno is invalid

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If invalid cellno is specified, command "freecell" will still
print the amount of available memory of node. As a fix, print
error instead.

* tools/virsh.c: "vshCommandOptInt", return -1 when value for
  parameter is specified, but invalid, which means strtol was
  failed, it won't affects other functions that use "vshCommandOptInt").
---
 tools/virsh.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 55e2a68..31f2a54 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2275,6 +2275,12 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
         return FALSE;

     cell = vshCommandOptInt(cmd, "cellno", &cell_given);
+
+    if (cell == -1) {
+        vshError(ctl, "%s", _("Invalid value for 'cellno', expecting an int"));
+        return FALSE;
+    }
+
     if (!cell_given) {
         memory = virNodeGetFreeMemory(ctl->conn);
         if (memory == 0)
@@ -10440,13 +10446,17 @@ vshCommandOptInt(const vshCmd *cmd, const char *name, int *found)

     if ((arg != NULL) && (arg->data != NULL)) {
         res = strtol(arg->data, &end_p, 10);
-        if ((arg->data == end_p) || (*end_p!= 0))
+
+        if ((arg->data == end_p) || (*end_p!= 0)) {
             num_found = FALSE;
-        else
+            res = -1;
+        } else
             num_found = TRUE;
     }
+
     if (found)
         *found = num_found;
+
     return res;
 }

--
1.7.3.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]