]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
expr: Enforce attr_policy compliance in nftnl_expr_set()
authorPhil Sutter <phil@nwl.cc>
Fri, 15 Dec 2023 15:32:30 +0000 (16:32 +0100)
committerPhil Sutter <phil@nwl.cc>
Wed, 6 Mar 2024 14:40:37 +0000 (15:40 +0100)
Every expression type defines an attr_policy array, so deny setting
attributes if not present. Also deny if maxlen field is non-zero and
lower than the given data_len.

Some attributes' max length is not fixed (e.g. NFTNL_EXPR_{TG,MT}_INFO )
or is not sensible to check (e.g.  NFTNL_EXPR_DYNSET_EXPR). The zero
maxlen "nop" is also used for deprecated attributes, just to not
silently ignore them.

Signed-off-by: Phil Sutter <phil@nwl.cc>
src/expr.c

index 74d211bcaa123670652e9c019b25e9bdba6f3df5..4e32189c6e8d0cb9c86acbdadf3155b55c46285d 100644 (file)
@@ -74,6 +74,13 @@ int nftnl_expr_set(struct nftnl_expr *expr, uint16_t type,
                if (type < NFTNL_EXPR_BASE || type > expr->ops->nftnl_max_attr)
                        return -1;
 
+               if (!expr->ops->attr_policy)
+                       return -1;
+
+               if (expr->ops->attr_policy[type].maxlen &&
+                   expr->ops->attr_policy[type].maxlen < data_len)
+                       return -1;
+
                if (expr->ops->set(expr, type, data, data_len) < 0)
                        return -1;
        }