Skip to contentSkip to conversation

datatype: fix crash when using basetype instead of symbolic constants

PATCH Superseded Pablo Neira Ayuso 2 participants 2 messages Nov 27, 2014 netfilter

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 datatype: fix crash when using basetype instead of symbolic constants

The following example:

 # nft add rule filter input ct state 8 accept
 Segmentation fault

leads to a crash because we have the following datatype relation:

ct_state -> bitmask -> integer

The bitmask, which is an intermediate basetype, has no parse() function, this leads to a crash in symbolic_constant_parse().

So let's default to the leaf basetype parser when the intermediate one has no specific parser() function.

Add a bugtrap too to catch inconsistent datatype configurations.

---
 src/datatype.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
src/datatype.c +11 -1
index 5f976aa..baeaea7 100644
@@ -128,7 +128,17 @@ struct error_record *symbolic_constant_parse(const struct expr *sym,
 	dtype = sym->dtype;
 	if (s->identifier == NULL) {
 		*res = NULL;
-		erec = sym->dtype->basetype->parse(sym, res);
+
+		if (sym->dtype->basetype->parse) {
+			erec = sym->dtype->basetype->parse(sym, res);
+		} else if (sym->dtype->basetype->basetype &&
+			   sym->dtype->basetype->basetype->parse) {
+			erec = sym->dtype->basetype->basetype->parse(sym, res);
+		} else {
+			BUG("cannot parse symbol %s with datatype %s\n",
+			    sym->identifier, sym->dtype->basetype->name);
+		}
+
 		if (erec != NULL)
 			return erec;
 		if (*res)
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 9 lines · Pablo Neira Ayuso

The following example:

 # nft add rule filter input ct state 8 accept
 Segmentation fault

leads to a crash because we have the following datatype relation:

ct_state -> bitmask -> integer

Quoted 7 lines

The bitmask, which is an intermediate basetype, has no parse() function, this leads to a crash in symbolic_constant_parse().

So let's default to the leaf basetype parser when the intermediate one has no specific parser() function.

Add a bugtrap too to catch inconsistent datatype configurations.

I think we should just walk down the chain until we find something with a parse function.