]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: string prefix expression must retain original length
authorFlorian Westphal <fw@strlen.de>
Sat, 9 Apr 2022 13:58:27 +0000 (15:58 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 13 Apr 2022 11:43:33 +0000 (13:43 +0200)
To make something like "eth*" work for interval sets (match
eth0, eth1, and so on...) we must treat the string as a 128 bit
integer.

Without this, segtree will do the wrong thing when applying the prefix,
because we generate the prefix based on 'eth*' as input, with a length of 3.

The correct import needs to be done on "eth\0\0\0\0\0\0\0...", i.e., if
the input buffer were an ipv6 address, it should look like "eth\0::",
not "::eth".

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/evaluate.c

index a20cc396b33fa3c3e2c765507f9438f31d546e75..788623137e58ef558ca9644459eee75a3070ad50 100644 (file)
@@ -338,9 +338,11 @@ static int expr_evaluate_string(struct eval_ctx *ctx, struct expr **exprp)
                *exprp = value;
                return 0;
        }
+
+       data[datalen] = 0;
        value = constant_expr_alloc(&expr->location, ctx->ectx.dtype,
                                    BYTEORDER_HOST_ENDIAN,
-                                   datalen * BITS_PER_BYTE, data);
+                                   expr->len, data);
 
        prefix = prefix_expr_alloc(&expr->location, value,
                                   datalen * BITS_PER_BYTE);