Skip to contentSkip to conversation

data_reg: xml: fix invalid veredict validation

PATCH In review Arturo Borrero 2 participants 2 messages May 29, 2013 – Jun 5, 2013 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 data_reg: xml: fix invalid veredict validation

Other kind of validations are used all over the XML parsing code. This validation is not valid anymore, and this patch update it.

---
 src/expr/data_reg.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
src/expr/data_reg.c +1 -3
index 71b10fe..12adc18 100644
@@ -64,10 +64,8 @@ static int nft_data_reg_verdict_xml_parse(union nft_data_reg *reg, char *xml)
 		return -1;
 	}
 
-	errno = 0;
 	tmp = strtoll(node->child->value.opaque, &endptr, 10);
-	if (tmp > INT_MAX || tmp < INT_MIN || errno != 0
-						|| strlen(endptr) > 0) {
+	if (tmp > INT_MAX || tmp < INT_MIN || *endptr) {
 		mxmlDelete(tree);
 		return -1;
 	}
#1 lore raw
Quoted 13 lines · Arturo Borrero

Other kind of validations are used all over the XML parsing code. This validation is not valid anymore, and this patch update it.

---
 src/expr/data_reg.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
src/expr/data_reg.c +0 -0
index 71b10fe..12adc18 100644

src/expr/data_reg.c static int nft_data_reg_verdict_xml_parse(union nft_data_reg *reg, char *xml) · line 68

Quoted 8 lines
src/expr/data_reg.c +1 -3
@@ -64,10 +64,8 @@ static int nft_data_reg_verdict_xml_parse(union nft_data_reg *reg, char *xml)
 		return -1;
 	}
 
-	errno = 0;
 	tmp = strtoll(node->child->value.opaque, &endptr, 10);
-	if (tmp > INT_MAX || tmp < INT_MIN || errno != 0
-						|| strlen(endptr) > 0) {
+	if (tmp > INT_MAX || tmp < INT_MIN || *endptr) {

I think it's time to add some helper function like nft_stroll. This function will take care of this tricky error handling and it will just return -1 in case of error. You can put this new function in src/utils.c and define it protype in internal.h.