From 8eddc307e9c35446d0c92bd0b7c7675f5afdfd5c Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Wed, 21 Oct 2015 12:43:29 +0200 Subject: [PATCH] virsh-domain: use correct base for virStrToLong_ui While parsing device addresses we should use correct base and don't count on auto-detect. For example, PCI address uses hex numbers, but each number starting with 0 will be auto-detected as octal number and that's wrong. Another wrong use-case is for PCI address if for example bus is 10, than it's incorrectly parsed as decimal number. PCI and CCW addresses have all values as hex numbers, IDE and SCSI addresses are in decimal numbers. Signed-off-by: Pavel Hrdina --- tools/virsh-domain.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 3f032f419a..12e85e3689 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -455,19 +455,19 @@ static int str2PCIAddress(const char *str, struct PCIAddress *pciAddr) domain = (char *)str; - if (virStrToLong_ui(domain, &bus, 0, &pciAddr->domain) != 0) + if (virStrToLong_ui(domain, &bus, 16, &pciAddr->domain) != 0) return -1; bus++; - if (virStrToLong_ui(bus, &slot, 0, &pciAddr->bus) != 0) + if (virStrToLong_ui(bus, &slot, 16, &pciAddr->bus) != 0) return -1; slot++; - if (virStrToLong_ui(slot, &function, 0, &pciAddr->slot) != 0) + if (virStrToLong_ui(slot, &function, 16, &pciAddr->slot) != 0) return -1; function++; - if (virStrToLong_ui(function, NULL, 0, &pciAddr->function) != 0) + if (virStrToLong_ui(function, NULL, 16, &pciAddr->function) != 0) return -1; return 0; @@ -484,15 +484,15 @@ static int str2SCSIAddress(const char *str, struct SCSIAddress *scsiAddr) controller = (char *)str; - if (virStrToLong_uip(controller, &bus, 0, &scsiAddr->controller) != 0) + if (virStrToLong_uip(controller, &bus, 10, &scsiAddr->controller) != 0) return -1; bus++; - if (virStrToLong_uip(bus, &unit, 0, &scsiAddr->bus) != 0) + if (virStrToLong_uip(bus, &unit, 10, &scsiAddr->bus) != 0) return -1; unit++; - if (virStrToLong_ullp(unit, NULL, 0, &scsiAddr->unit) != 0) + if (virStrToLong_ullp(unit, NULL, 10, &scsiAddr->unit) != 0) return -1; return 0; @@ -509,15 +509,15 @@ static int str2IDEAddress(const char *str, struct IDEAddress *ideAddr) controller = (char *)str; - if (virStrToLong_ui(controller, &bus, 0, &ideAddr->controller) != 0) + if (virStrToLong_ui(controller, &bus, 10, &ideAddr->controller) != 0) return -1; bus++; - if (virStrToLong_ui(bus, &unit, 0, &ideAddr->bus) != 0) + if (virStrToLong_ui(bus, &unit, 10, &ideAddr->bus) != 0) return -1; unit++; - if (virStrToLong_ui(unit, NULL, 0, &ideAddr->unit) != 0) + if (virStrToLong_ui(unit, NULL, 10, &ideAddr->unit) != 0) return -1; return 0; @@ -534,15 +534,15 @@ static int str2CCWAddress(const char *str, struct CCWAddress *ccwAddr) cssid = (char *)str; - if (virStrToLong_ui(cssid, &ssid, 0, &ccwAddr->cssid) != 0) + if (virStrToLong_ui(cssid, &ssid, 16, &ccwAddr->cssid) != 0) return -1; ssid++; - if (virStrToLong_ui(ssid, &devno, 0, &ccwAddr->ssid) != 0) + if (virStrToLong_ui(ssid, &devno, 16, &ccwAddr->ssid) != 0) return -1; devno++; - if (virStrToLong_ui(devno, NULL, 0, &ccwAddr->devno) != 0) + if (virStrToLong_ui(devno, NULL, 16, &ccwAddr->devno) != 0) return -1; return 0; @@ -739,8 +739,8 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) } else if (STRPREFIX((const char *)target, "hd")) { if (diskAddr.type == DISK_ADDR_TYPE_IDE) { virBufferAsprintf(&buf, - "
\n", + "
\n", diskAddr.addr.ide.controller, diskAddr.addr.ide.bus, diskAddr.addr.ide.unit); } else {