mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
virNWFilterRuleParse: Parse 'priority' via 'virXMLPropInt'
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>
This commit is contained in:
parent
f0c5da0f24
commit
3774fca88f
@ -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")))
|
||||
|
Loading…
Reference in New Issue
Block a user