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(a)redhat.com>
Reviewed-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/device_conf.c | 25 +++++--------------------
1 file changed, 5 insertions(+), 20 deletions(-)
diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
index 9b0b81b2cb..034f072df4 100644
--- a/src/conf/device_conf.c
+++ b/src/conf/device_conf.c
@@ -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 (virXMLPropEnum(node, "state", virNetDevIfStateTypeFromString,
+ VIR_XML_PROP_NONE, &lnk->state) < 0)
+ return -1;
- if (speedStr &&
- virStrToLong_ui(speedStr, NULL, 10, &lnk->speed) < 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("Unable to parse link speed: %s"),
- speedStr);
+ if (virXMLPropUInt(node, "speed", 10, VIR_XML_PROP_NONE,
&lnk->speed) < 0)
return -1;
- }
+
return 0;
}
--
2.26.3