]> xenbits.xensource.com Git - libvirt.git/commitdiff
virNWFilterRuleParse: Parse 'priority' via 'virXMLPropInt'
authorPeter Krempa <pkrempa@redhat.com>
Thu, 16 Feb 2023 12:20:03 +0000 (13:20 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 5 Jun 2023 11:23:06 +0000 (13:23 +0200)
Use modern parsing. Invalid numbers are now rejected. Semantis for
numbers out of range is preserved.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/nwfilter_conf.c

index 13c6096fcdd7e8d1d5cb90a2b3d549c27676d67c..b7400b553a9023d7fa82f1187155102b804207f0 100644 (file)
@@ -2373,18 +2373,15 @@ virNWFilterRuleDefFixup(virNWFilterRuleDef *rule)
 static virNWFilterRuleDef *
 virNWFilterRuleParse(xmlNodePtr node)
 {
-    g_autofree char *prio = NULL;
     g_autofree char *statematch = NULL;
     bool found;
     int found_i = 0;
-    int priority;
 
     xmlNodePtr cur;
     g_autoptr(virNWFilterRuleDef) ret = NULL;
 
     ret = g_new0(virNWFilterRuleDef, 1);
 
-    prio       = virXMLPropString(node, "priority");
     statematch = virXMLPropString(node, "statematch");
 
     if (virXMLPropEnum(node, "action", virNWFilterRuleActionTypeFromString,
@@ -2395,15 +2392,12 @@ virNWFilterRuleParse(xmlNodePtr node)
                        VIR_XML_PROP_REQUIRED, &ret->tt) < 0)
         return NULL;
 
-    ret->priority = MAX_RULE_PRIORITY / 2;
+    if (virXMLPropInt(node, "priority", 10, VIR_XML_PROP_NONE, &ret->priority,
+                      MAX_RULE_PRIORITY / 2) < 0)
+        return NULL;
 
-    if (prio) {
-        if (virStrToLong_i(prio, NULL, 10, &priority) >= 0) {
-            if (priority <= MAX_RULE_PRIORITY &&
-                priority >= MIN_RULE_PRIORITY)
-                ret->priority = priority;
-        }
-    }
+    if (ret->priority > MAX_RULE_PRIORITY || ret->priority < MIN_RULE_PRIORITY)
+        ret->priority = MAX_RULE_PRIORITY / 2;
 
     if (statematch &&
         (STREQ(statematch, "0") || STRCASEEQ(statematch, "false")))