From: Phil Sutter Date: Fri, 16 May 2025 11:28:19 +0000 (+0200) Subject: netlink_delinearize: Replace some BUG()s by error messages X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9f2a11aa15422333d1812501dd4f294348d6e0d5;p=thirdparty%2Fnftables.git netlink_delinearize: Replace some BUG()s by error messages 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 Reviewed-by: Pablo Neira Ayuso --- diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c index f7c10fb5..48a3e33a 100644 --- a/src/netlink_delinearize.c +++ b/src/netlink_delinearize.c @@ -605,7 +605,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); @@ -616,6 +617,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; @@ -627,7 +629,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; @@ -635,8 +637,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); @@ -733,8 +736,10 @@ static void netlink_parse_inner(struct netlink_parse_ctx *ctx, expr->meta.inner_desc = inner_desc; break; default: - assert(0); - break; + netlink_error(ctx, loc, "Unsupported inner expression type %s", + expr_ops(expr)->name); + expr_free(expr); + return; } netlink_set_register(ctx, ctx->inner_reg, expr);