]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
netlink_delinearize: Replace some BUG()s by error messages
authorPhil Sutter <phil@nwl.cc>
Fri, 16 May 2025 11:28:19 +0000 (13:28 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 13 Aug 2025 17:22:10 +0000 (19:22 +0200)
commit 9f2a11aa15422333d1812501dd4f294348d6e0d5 upstream.

Netlink parser tries to keep going despite errors. Faced with an
incompatible ruleset, this is much more user-friendly than exiting the
program upon the first obstacle. This patch fixes three more spots to
support this.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/netlink_delinearize.c

index 990032f73f4e7ec402d02acf06adca1d7af3c67f..14cb8f6c00c3219897a6846d736dca127bcd1ac0 100644 (file)
@@ -563,7 +563,8 @@ static void netlink_parse_bitwise(struct netlink_parse_ctx *ctx,
                                                   sreg, left);
                break;
        default:
-               BUG("invalid bitwise operation %u\n", op);
+               return netlink_error(ctx, loc,
+                                    "Invalid bitwise operation %u", op);
        }
 
        dreg = netlink_parse_register(nle, NFTNL_EXPR_BITWISE_DREG);
@@ -574,6 +575,7 @@ static void netlink_parse_byteorder(struct netlink_parse_ctx *ctx,
                                    const struct location *loc,
                                    const struct nftnl_expr *nle)
 {
+       uint32_t opval = nftnl_expr_get_u32(nle, NFTNL_EXPR_BYTEORDER_OP);
        enum nft_registers sreg, dreg;
        struct expr *expr, *arg;
        enum ops op;
@@ -585,7 +587,7 @@ static void netlink_parse_byteorder(struct netlink_parse_ctx *ctx,
                                     "Byteorder expression has no left "
                                     "hand side");
 
-       switch (nftnl_expr_get_u32(nle, NFTNL_EXPR_BYTEORDER_OP)) {
+       switch (opval) {
        case NFT_BYTEORDER_NTOH:
                op = OP_NTOH;
                break;
@@ -593,8 +595,9 @@ static void netlink_parse_byteorder(struct netlink_parse_ctx *ctx,
                op = OP_HTON;
                break;
        default:
-               BUG("invalid byteorder operation %u\n",
-                   nftnl_expr_get_u32(nle, NFTNL_EXPR_BYTEORDER_OP));
+               expr_free(arg);
+               return netlink_error(ctx, loc,
+                                    "Invalid byteorder operation %u", opval);
        }
 
        expr = unary_expr_alloc(loc, op, arg);