1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-04-01 20:05:19 +00:00

virInterfaceLinkParseXML: Use virXMLProp*

This strictens the parser to disallow negative values (interpreted as
`UINT_MAX + value + 1`) for attribute `speed`, which does not make sense for
a value measured in Mbits per second.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Tim Wiederhake 2021-04-21 14:08:08 +02:00 committed by Peter Krempa
parent 8f7cb1d243
commit 122fcdf14f

View File

@ -465,28 +465,13 @@ int
virInterfaceLinkParseXML(xmlNodePtr node,
virNetDevIfLink *lnk)
{
int state;
g_autofree char *stateStr = virXMLPropString(node, "state");
g_autofree char *speedStr = virXMLPropString(node, "speed");
if (stateStr) {
if ((state = virNetDevIfStateTypeFromString(stateStr)) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("unknown link state: %s"),
stateStr);
return -1;
}
lnk->state = state;
}
if (speedStr &&
virStrToLong_ui(speedStr, NULL, 10, &lnk->speed) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Unable to parse link speed: %s"),
speedStr);
if (virXMLPropEnum(node, "state", virNetDevIfStateTypeFromString,
VIR_XML_PROP_NONE, &lnk->state) < 0)
return -1;
}
if (virXMLPropUInt(node, "speed", 10, VIR_XML_PROP_NONE, &lnk->speed) < 0)
return -1;
return 0;
}