]> git.ipfire.org Git - thirdparty/nftables.git/commit
evaluate: support shifts larger than the width of the left operand
authorPablo Neira Ayuso <pablo@netfilter.org>
Fri, 17 Mar 2023 09:16:40 +0000 (10:16 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 22 Jan 2025 21:10:05 +0000 (22:10 +0100)
commitc6b3dfeec9cdf676de2c8465063e68f3e8b0049f
tree0907c1ad3d0bc174d64d072f61d27275b1faed4e
parent306a7841263567d901d9ea91a9e2fe4b07c04e2c
evaluate: support shifts larger than the width of the left operand

commit edecd58755a84dbe8f36795f619189490eeb3ef1 upstream.

If we want to left-shift a value of narrower type and assign the result
to a variable of a wider type, we are constrained to only shifting up to
the width of the narrower type.  Thus:

  add rule t c meta mark set ip dscp << 2

works, but:

  add rule t c meta mark set ip dscp << 8

does not, even though the lvalue is large enough to accommodate the
result.

Upgrade the maximum length based on the statement datatype length, which
is provided via context, if it is larger than expression lvalue.

Update netlink_delinearize.c to handle the case where the length of a
shift expression does not match that of its left-hand operand.

Based on patch from Jeremy Sowden.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/rule.h
src/evaluate.c
src/netlink_delinearize.c