提交 df6551fe 编写于 作者: J Ján Tomko

virsh: reject more negative numbers

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
上级 2da7f545
...@@ -438,19 +438,19 @@ static int str2PCIAddress(const char *str, struct PCIAddress *pciAddr) ...@@ -438,19 +438,19 @@ static int str2PCIAddress(const char *str, struct PCIAddress *pciAddr)
domain = (char *)str; domain = (char *)str;
if (virStrToLong_ui(domain, &bus, 16, &pciAddr->domain) != 0) if (virStrToLong_uip(domain, &bus, 16, &pciAddr->domain) != 0)
return -1; return -1;
bus++; bus++;
if (virStrToLong_ui(bus, &slot, 16, &pciAddr->bus) != 0) if (virStrToLong_uip(bus, &slot, 16, &pciAddr->bus) != 0)
return -1; return -1;
slot++; slot++;
if (virStrToLong_ui(slot, &function, 16, &pciAddr->slot) != 0) if (virStrToLong_uip(slot, &function, 16, &pciAddr->slot) != 0)
return -1; return -1;
function++; function++;
if (virStrToLong_ui(function, NULL, 16, &pciAddr->function) != 0) if (virStrToLong_uip(function, NULL, 16, &pciAddr->function) != 0)
return -1; return -1;
return 0; return 0;
...@@ -492,15 +492,15 @@ static int str2IDEAddress(const char *str, struct IDEAddress *ideAddr) ...@@ -492,15 +492,15 @@ static int str2IDEAddress(const char *str, struct IDEAddress *ideAddr)
controller = (char *)str; controller = (char *)str;
if (virStrToLong_ui(controller, &bus, 10, &ideAddr->controller) != 0) if (virStrToLong_uip(controller, &bus, 10, &ideAddr->controller) != 0)
return -1; return -1;
bus++; bus++;
if (virStrToLong_ui(bus, &unit, 10, &ideAddr->bus) != 0) if (virStrToLong_uip(bus, &unit, 10, &ideAddr->bus) != 0)
return -1; return -1;
unit++; unit++;
if (virStrToLong_ui(unit, NULL, 10, &ideAddr->unit) != 0) if (virStrToLong_uip(unit, NULL, 10, &ideAddr->unit) != 0)
return -1; return -1;
return 0; return 0;
...@@ -517,15 +517,15 @@ static int str2CCWAddress(const char *str, struct CCWAddress *ccwAddr) ...@@ -517,15 +517,15 @@ static int str2CCWAddress(const char *str, struct CCWAddress *ccwAddr)
cssid = (char *)str; cssid = (char *)str;
if (virStrToLong_ui(cssid, &ssid, 16, &ccwAddr->cssid) != 0) if (virStrToLong_uip(cssid, &ssid, 16, &ccwAddr->cssid) != 0)
return -1; return -1;
ssid++; ssid++;
if (virStrToLong_ui(ssid, &devno, 16, &ccwAddr->ssid) != 0) if (virStrToLong_uip(ssid, &devno, 16, &ccwAddr->ssid) != 0)
return -1; return -1;
devno++; devno++;
if (virStrToLong_ui(devno, NULL, 16, &ccwAddr->devno) != 0) if (virStrToLong_uip(devno, NULL, 16, &ccwAddr->devno) != 0)
return -1; return -1;
return 0; return 0;
...@@ -8428,7 +8428,7 @@ virshKeyCodeGetInt(const char *key_name) ...@@ -8428,7 +8428,7 @@ virshKeyCodeGetInt(const char *key_name)
{ {
unsigned int val; 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 -1;
return val; return val;
} }
......
...@@ -209,7 +209,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) ...@@ -209,7 +209,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
for (i = 0; i < nodes_cnt; i++) { for (i = 0; i < nodes_cnt; i++) {
unsigned long id; unsigned long id;
char *val = virXMLPropString(nodes[i], "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")); vshError(ctl, "%s", _("conversion from string failed"));
VIR_FREE(val); VIR_FREE(val);
goto cleanup; goto cleanup;
...@@ -355,7 +355,7 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) ...@@ -355,7 +355,7 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
for (i = 0; i < nodes_cnt; i++) { for (i = 0; i < nodes_cnt; i++) {
char *val = virXMLPropString(nodes[i], "size"); 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); vshError(ctl, _("unable to parse page size: %s"), val);
VIR_FREE(val); VIR_FREE(val);
goto cleanup; goto cleanup;
...@@ -554,7 +554,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) ...@@ -554,7 +554,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd)
for (i = 0; i < nodes_cnt; i++) { for (i = 0; i < nodes_cnt; i++) {
unsigned long id; unsigned long id;
char *val = virXMLPropString(nodes[i], "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")); vshError(ctl, "%s", _("conversion from string failed"));
VIR_FREE(val); VIR_FREE(val);
goto cleanup; goto cleanup;
......
...@@ -206,7 +206,7 @@ static int ...@@ -206,7 +206,7 @@ static int
virshVolSize(const char *data, unsigned long long *val) virshVolSize(const char *data, unsigned long long *val)
{ {
char *end; char *end;
if (virStrToLong_ull(data, &end, 10, val) < 0) if (virStrToLong_ullp(data, &end, 10, val) < 0)
return -1; return -1;
return virScaleInteger(val, end, 1, ULLONG_MAX); return virScaleInteger(val, end, 1, ULLONG_MAX);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册