Skip to contentSkip to conversation

meta: fix error checks in tc handle parser

PATCH In review Florian Westphal 2 participants 4 messages Feb 1, 2016 – Feb 16, 2016 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 meta: fix error checks in tc handle parser

'meta priority foobar' did not return an error -- instead we used min/max values with undefined content.

---
 src/meta.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
src/meta.c +3 -3
index 8cbc974..7f12f0c 100644
@@ -100,17 +100,17 @@ static struct error_record *tchandle_type_parse(const struct expr *sym,
 	else if (strcmp(sym->identifier, "none") == 0)
 		handle = TC_H_UNSPEC;
 	else if (sym->identifier[0] == ':') {
-		if (sscanf(sym->identifier, ":%04x", &handle) < 0)
+		if (sscanf(sym->identifier, ":%04x", &handle) != 1)
 			goto err;
 	} else if (sym->identifier[strlen(sym->identifier)-1] == ':') {
-		if (sscanf(sym->identifier, "%04x:", &handle) < 0)
+		if (sscanf(sym->identifier, "%04x:", &handle) != 1)
 			goto err;
 
 		handle <<= 16;
 	} else {
 		uint32_t min, max;
 
-		if (sscanf(sym->identifier, "%04x:%04x", &min, &max) < 0)
+		if (sscanf(sym->identifier, "%04x:%04x", &min, &max) != 2)
 			goto err;
 
 		handle = max << 16 | min;
Signature · 1 line
2.4.10
author maintainer
#2 lore raw
Quoted 7 lines · Pablo Neira Ayuso
Quoted 4 lines · Florian Westphal

'meta priority foobar' did not return an error -- instead we used min/max values with undefined content.

Fine with me. IIRC, the scanner is still broken though.

Ho-hum. It is. And I don't see how this can be fixed. Teaching scanner.l about

tchandle {hexdigit}{4}:{hexdigit}{4}

breaks

tcp sport vmap { 1225:accept, }

( 1225:acc is handle).