mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 15:15:25 +00:00
Replace sscanf in legacy device address parsing
Parsing is stricter now and doesn't accept trailing characters after the actual <domain>:<bus>:<slot> sequence anymore.
This commit is contained in:
parent
e813200714
commit
2072d63c5b
@ -1290,6 +1290,23 @@ cleanup:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
virDomainParseLegacyDeviceAddress(char *devaddr,
|
||||||
|
virDomainDevicePCIAddressPtr pci)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
/* expected format: <domain>:<bus>:<slot> */
|
||||||
|
if (/* domain */
|
||||||
|
virStrToLong_ui(devaddr, &tmp, 16, &pci->domain) < 0 || *tmp != ':' ||
|
||||||
|
/* bus */
|
||||||
|
virStrToLong_ui(tmp + 1, &tmp, 16, &pci->bus) < 0 || *tmp != ':' ||
|
||||||
|
/* slot */
|
||||||
|
virStrToLong_ui(tmp + 1, NULL, 16, &pci->slot) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
virDomainDiskDefAssignAddress(virDomainDiskDefPtr def)
|
virDomainDiskDefAssignAddress(virDomainDiskDefPtr def)
|
||||||
@ -1541,10 +1558,8 @@ virDomainDiskDefParseXML(xmlNodePtr node,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (devaddr) {
|
if (devaddr) {
|
||||||
if (sscanf(devaddr, "%x:%x:%x",
|
if (virDomainParseLegacyDeviceAddress(devaddr,
|
||||||
&def->info.addr.pci.domain,
|
&def->info.addr.pci) < 0) {
|
||||||
&def->info.addr.pci.bus,
|
|
||||||
&def->info.addr.pci.slot) < 3) {
|
|
||||||
virDomainReportError(VIR_ERR_INTERNAL_ERROR,
|
virDomainReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Unable to parse devaddr parameter '%s'"),
|
_("Unable to parse devaddr parameter '%s'"),
|
||||||
devaddr);
|
devaddr);
|
||||||
@ -1901,10 +1916,8 @@ virDomainNetDefParseXML(virCapsPtr caps,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (devaddr) {
|
if (devaddr) {
|
||||||
if (sscanf(devaddr, "%x:%x:%x",
|
if (virDomainParseLegacyDeviceAddress(devaddr,
|
||||||
&def->info.addr.pci.domain,
|
&def->info.addr.pci) < 0) {
|
||||||
&def->info.addr.pci.bus,
|
|
||||||
&def->info.addr.pci.slot) < 3) {
|
|
||||||
virDomainReportError(VIR_ERR_INTERNAL_ERROR,
|
virDomainReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Unable to parse devaddr parameter '%s'"),
|
_("Unable to parse devaddr parameter '%s'"),
|
||||||
devaddr);
|
devaddr);
|
||||||
@ -3222,10 +3235,8 @@ virDomainHostdevSubsysPciDefParseXML(const xmlNodePtr node,
|
|||||||
/* Legacy back-compat. Don't add any more attributes here */
|
/* Legacy back-compat. Don't add any more attributes here */
|
||||||
char *devaddr = virXMLPropString(cur, "devaddr");
|
char *devaddr = virXMLPropString(cur, "devaddr");
|
||||||
if (devaddr &&
|
if (devaddr &&
|
||||||
sscanf(devaddr, "%x:%x:%x",
|
virDomainParseLegacyDeviceAddress(devaddr,
|
||||||
&def->info.addr.pci.domain,
|
&def->info.addr.pci) < 0) {
|
||||||
&def->info.addr.pci.bus,
|
|
||||||
&def->info.addr.pci.slot) < 3) {
|
|
||||||
virDomainReportError(VIR_ERR_INTERNAL_ERROR,
|
virDomainReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Unable to parse devaddr parameter '%s'"),
|
_("Unable to parse devaddr parameter '%s'"),
|
||||||
devaddr);
|
devaddr);
|
||||||
|
Loading…
Reference in New Issue
Block a user