]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
netlink: don't crash when set elements are not evaluated as expected
authorFlorian Westphal <fw@strlen.de>
Tue, 30 Mar 2021 23:26:19 +0000 (01:26 +0200)
committerFlorian Westphal <fw@strlen.de>
Thu, 1 Apr 2021 12:22:13 +0000 (14:22 +0200)
define foo = 2001:db8:123::/48

table inet filter {
set foo {
typeof ip6 saddr
elements = $foo
}
}

gives crash.  This now exits with:

stdin:1:14-30: Error: Unexpected initial set type prefix
define foo = 2001:db8:123::/48
             ^^^^^^^^^^^^^^^^^

For literals, bison parser protects us, as it enforces
'elements = { 2001:... '.

For 'elements = $foo' we can't detect it at parsing stage as the '$foo'
symbol might as well evaluate to "{ 2001, ...}" (i.e. we can't do a
set element allocation).

So at least detect this from set instantiaton.

Signed-off-by: Florian Westphal <fw@strlen.de>
src/evaluate.c
src/netlink.c

index cebf7cb8ef2c58878fcebb9eb869f0cfb57bc28d..8105d8d5c8a9f8ec5799e1c6fa53f92f4d8de2c8 100644 (file)
@@ -3787,6 +3787,9 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set)
                                   set->key->byteorder, set->key->len, 0);
                if (expr_evaluate(ctx, &set->init) < 0)
                        return -1;
+               if (set->init->etype != EXPR_SET)
+                       return expr_error(ctx->msgs, set->init, "Set %s: Unexpected initial type %s, missing { }?",
+                                         set->handle.set.name, expr_name(set->init));
        }
        ctx->set = NULL;
 
index 103fdbd10690660412402ec33cc62c18d7b0d60b..97ae88c72789441cc788655639bb66ff308c273f 100644 (file)
@@ -120,6 +120,9 @@ static struct nftnl_set_elem *alloc_nftnl_setelem(const struct expr *set,
        } else {
                elem = expr;
        }
+       if (elem->etype != EXPR_SET_ELEM)
+               BUG("Unexpected expression type: got %d\n", elem->etype);
+
        key = elem->key;
 
        netlink_gen_data(key, &nld);