From a23fefdf461c98c98e32e61440df96cf5dd43a51 Mon Sep 17 00:00:00 2001 From: Luyao Huang Date: Mon, 8 Dec 2014 16:27:26 +0800 Subject: [PATCH] conf: forbid negative number in address(like controller, bus, slot...) https://bugzilla.redhat.com/show_bug.cgi?id=1171582 When we edit a negative controller address number to a device, some of them will auto generate a controller with invalid index number. This will make guest disappear after restart libvirtd. Instead of allowing negative number for controller index, we should forbid negative number in these place (we did this before, but after f18c02ec, virStrToLong_ui changed to allow negative number). Therefore switch to virStrToLong_uip in these places. Signed-off-by: Luyao Huang Signed-off-by: Michal Privoznik --- src/conf/device_conf.c | 8 ++++---- src/conf/domain_conf.c | 32 ++++++++++++++++---------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index b3b04e1477..5ffe159b79 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -64,28 +64,28 @@ virDevicePCIAddressParseXML(xmlNodePtr node, multi = virXMLPropString(node, "multifunction"); if (domain && - virStrToLong_ui(domain, NULL, 0, &addr->domain) < 0) { + virStrToLong_uip(domain, NULL, 0, &addr->domain) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse
'domain' attribute")); goto cleanup; } if (bus && - virStrToLong_ui(bus, NULL, 0, &addr->bus) < 0) { + virStrToLong_uip(bus, NULL, 0, &addr->bus) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse
'bus' attribute")); goto cleanup; } if (slot && - virStrToLong_ui(slot, NULL, 0, &addr->slot) < 0) { + virStrToLong_uip(slot, NULL, 0, &addr->slot) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse
'slot' attribute")); goto cleanup; } if (function && - virStrToLong_ui(function, NULL, 0, &addr->function) < 0) { + virStrToLong_uip(function, NULL, 0, &addr->function) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse
'function' attribute")); goto cleanup; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 843cdecf13..db3369e20a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3455,28 +3455,28 @@ virDomainDeviceDriveAddressParseXML(xmlNodePtr node, unit = virXMLPropString(node, "unit"); if (controller && - virStrToLong_ui(controller, NULL, 10, &addr->controller) < 0) { + virStrToLong_uip(controller, NULL, 10, &addr->controller) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse
'controller' attribute")); goto cleanup; } if (bus && - virStrToLong_ui(bus, NULL, 10, &addr->bus) < 0) { + virStrToLong_uip(bus, NULL, 10, &addr->bus) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse
'bus' attribute")); goto cleanup; } if (target && - virStrToLong_ui(target, NULL, 10, &addr->target) < 0) { + virStrToLong_uip(target, NULL, 10, &addr->target) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse
'target' attribute")); goto cleanup; } if (unit && - virStrToLong_ui(unit, NULL, 10, &addr->unit) < 0) { + virStrToLong_uip(unit, NULL, 10, &addr->unit) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse
'unit' attribute")); goto cleanup; @@ -3509,21 +3509,21 @@ virDomainDeviceVirtioSerialAddressParseXML( port = virXMLPropString(node, "port"); if (controller && - virStrToLong_ui(controller, NULL, 10, &addr->controller) < 0) { + virStrToLong_uip(controller, NULL, 10, &addr->controller) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse
'controller' attribute")); goto cleanup; } if (bus && - virStrToLong_ui(bus, NULL, 10, &addr->bus) < 0) { + virStrToLong_uip(bus, NULL, 10, &addr->bus) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse
'bus' attribute")); goto cleanup; } if (port && - virStrToLong_ui(port, NULL, 10, &addr->port) < 0) { + virStrToLong_uip(port, NULL, 10, &addr->port) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse
'port' attribute")); goto cleanup; @@ -3555,19 +3555,19 @@ virDomainDeviceCCWAddressParseXML(xmlNodePtr node, if (cssid && ssid && devno) { if (cssid && - virStrToLong_ui(cssid, NULL, 0, &addr->cssid) < 0) { + virStrToLong_uip(cssid, NULL, 0, &addr->cssid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse
'cssid' attribute")); goto cleanup; } if (ssid && - virStrToLong_ui(ssid, NULL, 0, &addr->ssid) < 0) { + virStrToLong_uip(ssid, NULL, 0, &addr->ssid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse
'ssid' attribute")); goto cleanup; } if (devno && - virStrToLong_ui(devno, NULL, 0, &addr->devno) < 0) { + virStrToLong_uip(devno, NULL, 0, &addr->devno) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse
'devno' attribute")); goto cleanup; @@ -3609,14 +3609,14 @@ virDomainDeviceCcidAddressParseXML(xmlNodePtr node, slot = virXMLPropString(node, "slot"); if (controller && - virStrToLong_ui(controller, NULL, 10, &addr->controller) < 0) { + virStrToLong_uip(controller, NULL, 10, &addr->controller) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse
'controller' attribute")); goto cleanup; } if (slot && - virStrToLong_ui(slot, NULL, 10, &addr->slot) < 0) { + virStrToLong_uip(slot, NULL, 10, &addr->slot) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse
'slot' attribute")); goto cleanup; @@ -3644,7 +3644,7 @@ virDomainDeviceUSBAddressParseXML(xmlNodePtr node, bus = virXMLPropString(node, "bus"); if (port && - ((virStrToLong_ui(port, &tmp, 10, &p) < 0 || (*tmp != '\0' && *tmp != '.')) || + ((virStrToLong_uip(port, &tmp, 10, &p) < 0 || (*tmp != '\0' && *tmp != '.')) || (*tmp == '.' && (virStrToLong_ui(tmp + 1, &tmp, 10, &p) < 0 || (*tmp != '\0' && *tmp != '.'))) || (*tmp == '.' && (virStrToLong_ui(tmp + 1, &tmp, 10, &p) < 0 || (*tmp != '\0' && *tmp != '.'))) || (*tmp == '.' && (virStrToLong_ui(tmp + 1, &tmp, 10, &p) < 0 || (*tmp != '\0'))))) { @@ -3657,7 +3657,7 @@ virDomainDeviceUSBAddressParseXML(xmlNodePtr node, port = NULL; if (bus && - virStrToLong_ui(bus, NULL, 10, &addr->bus) < 0) { + virStrToLong_uip(bus, NULL, 10, &addr->bus) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse
'bus' attribute")); goto cleanup; @@ -3779,14 +3779,14 @@ virDomainDeviceISAAddressParseXML(xmlNodePtr node, irq = virXMLPropString(node, "irq"); if (iobase && - virStrToLong_ui(iobase, NULL, 16, &addr->iobase) < 0) { + virStrToLong_uip(iobase, NULL, 16, &addr->iobase) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Cannot parse
'iobase' attribute")); goto cleanup; } if (irq && - virStrToLong_ui(irq, NULL, 16, &addr->irq) < 0) { + virStrToLong_uip(irq, NULL, 16, &addr->irq) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Cannot parse
'irq' attribute")); goto cleanup; -- GitLab