]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: reject more negative numbers
authorJán Tomko <jtomko@redhat.com>
Mon, 27 Mar 2017 12:17:42 +0000 (14:17 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 27 Mar 2017 15:20:03 +0000 (17:20 +0200)
Be more positive and reject negative numbers where we don't
allow them by using the virStrToLong variants with 'p'.

https://bugzilla.redhat.com/show_bug.cgi?id=1436119

tools/virsh-domain.c
tools/virsh-host.c
tools/virsh-volume.c

index 2269146850433461b3ff59e02c919f7585453cbf..4b6c13ce43681f1ed8e2c16ee44cca072e752afa 100644 (file)
@@ -438,19 +438,19 @@ static int str2PCIAddress(const char *str, struct PCIAddress *pciAddr)
 
     domain = (char *)str;
 
-    if (virStrToLong_ui(domain, &bus, 16, &pciAddr->domain) != 0)
+    if (virStrToLong_uip(domain, &bus, 16, &pciAddr->domain) != 0)
         return -1;
 
     bus++;
-    if (virStrToLong_ui(bus, &slot, 16, &pciAddr->bus) != 0)
+    if (virStrToLong_uip(bus, &slot, 16, &pciAddr->bus) != 0)
         return -1;
 
     slot++;
-    if (virStrToLong_ui(slot, &function, 16, &pciAddr->slot) != 0)
+    if (virStrToLong_uip(slot, &function, 16, &pciAddr->slot) != 0)
         return -1;
 
     function++;
-    if (virStrToLong_ui(function, NULL, 16, &pciAddr->function) != 0)
+    if (virStrToLong_uip(function, NULL, 16, &pciAddr->function) != 0)
         return -1;
 
     return 0;
@@ -492,15 +492,15 @@ static int str2IDEAddress(const char *str, struct IDEAddress *ideAddr)
 
     controller = (char *)str;
 
-    if (virStrToLong_ui(controller, &bus, 10, &ideAddr->controller) != 0)
+    if (virStrToLong_uip(controller, &bus, 10, &ideAddr->controller) != 0)
         return -1;
 
     bus++;
-    if (virStrToLong_ui(bus, &unit, 10, &ideAddr->bus) != 0)
+    if (virStrToLong_uip(bus, &unit, 10, &ideAddr->bus) != 0)
         return -1;
 
     unit++;
-    if (virStrToLong_ui(unit, NULL, 10, &ideAddr->unit) != 0)
+    if (virStrToLong_uip(unit, NULL, 10, &ideAddr->unit) != 0)
         return -1;
 
     return 0;
@@ -517,15 +517,15 @@ static int str2CCWAddress(const char *str, struct CCWAddress *ccwAddr)
 
     cssid = (char *)str;
 
-    if (virStrToLong_ui(cssid, &ssid, 16, &ccwAddr->cssid) != 0)
+    if (virStrToLong_uip(cssid, &ssid, 16, &ccwAddr->cssid) != 0)
         return -1;
 
     ssid++;
-    if (virStrToLong_ui(ssid, &devno, 16, &ccwAddr->ssid) != 0)
+    if (virStrToLong_uip(ssid, &devno, 16, &ccwAddr->ssid) != 0)
         return -1;
 
     devno++;
-    if (virStrToLong_ui(devno, NULL, 16, &ccwAddr->devno) != 0)
+    if (virStrToLong_uip(devno, NULL, 16, &ccwAddr->devno) != 0)
         return -1;
 
     return 0;
@@ -8428,7 +8428,7 @@ virshKeyCodeGetInt(const char *key_name)
 {
     unsigned int val;
 
-    if (virStrToLong_ui(key_name, NULL, 0, &val) < 0 || val > 0xffff)
+    if (virStrToLong_uip(key_name, NULL, 0, &val) < 0 || val > 0xffff)
         return -1;
     return val;
 }
index 24ebde2801852af1db54a17a13954f6c372c7bb3..3b86c75fa446d683b8ebddf2bc8b9417c0c8e994 100644 (file)
@@ -209,7 +209,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
         for (i = 0; i < nodes_cnt; i++) {
             unsigned long id;
             char *val = virXMLPropString(nodes[i], "id");
-            if (virStrToLong_ul(val, NULL, 10, &id)) {
+            if (virStrToLong_ulp(val, NULL, 10, &id)) {
                 vshError(ctl, "%s", _("conversion from string failed"));
                 VIR_FREE(val);
                 goto cleanup;
@@ -355,7 +355,7 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
             for (i = 0; i < nodes_cnt; i++) {
                 char *val = virXMLPropString(nodes[i], "size");
 
-                if (virStrToLong_ui(val, NULL, 10, &pagesize[i]) < 0) {
+                if (virStrToLong_uip(val, NULL, 10, &pagesize[i]) < 0) {
                     vshError(ctl, _("unable to parse page size: %s"), val);
                     VIR_FREE(val);
                     goto cleanup;
@@ -554,7 +554,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd)
         for (i = 0; i < nodes_cnt; i++) {
             unsigned long id;
             char *val = virXMLPropString(nodes[i], "id");
-            if (virStrToLong_ul(val, NULL, 10, &id)) {
+            if (virStrToLong_ulp(val, NULL, 10, &id)) {
                 vshError(ctl, "%s", _("conversion from string failed"));
                 VIR_FREE(val);
                 goto cleanup;
index 02ed044e41ec27ff7bf0d310ced650662386b1de..32ffb8149ea1b62e8740e190e67179e6275b34aa 100644 (file)
@@ -206,7 +206,7 @@ static int
 virshVolSize(const char *data, unsigned long long *val)
 {
     char *end;
-    if (virStrToLong_ull(data, &end, 10, val) < 0)
+    if (virStrToLong_ullp(data, &end, 10, val) < 0)
         return -1;
     return virScaleInteger(val, end, 1, ULLONG_MAX);
 }