]> git.ipfire.org Git - thirdparty/nftables.git/commit
expression: cleanup expr_ops_by_type() and handle u32 input
authorThomas Haller <thaller@redhat.com>
Wed, 20 Sep 2023 14:26:08 +0000 (16:26 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 13 Aug 2025 16:55:50 +0000 (18:55 +0200)
commit1c1a84e987d25a8bf6a804492d7e9fd0c225e7df
treeaadb9cac3d48f655ac9c6895f26853a1406c68fa
parentb92b2e6d6355902e31581eaafe380f3c3cb7b041
expression: cleanup expr_ops_by_type() and handle u32 input

commit 3d0ce3c19d319a5aae806b617905cfa1ee7f87f4 upstream.

Make fewer assumptions about the underlying integer type of the enum.
Instead, be clear about where we have an untrusted uint32_t from netlink
and an enum. Rename expr_ops_by_type() to expr_ops_by_type_u32() to make
this clearer. Later we might make the enum as packed, when this starts
to matter more.

Also, only the code path expr_ops() wants strict validation and assert
against valid enum values. Move the assertion out of
__expr_ops_by_type(). Then expr_ops_by_type_u32() does not need to
duplicate the handling of EXPR_INVALID. We still need to duplicate the
check against EXPR_MAX, to ensure that the uint32_t value can be cast to
an enum value.

[ Remove cast on EXPR_MAX. --pablo ]

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/expression.h
src/expression.c
src/netlink.c