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-Tag: v1.0.6.1~58 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=04be0936ac7ff0d0538777073918f7a11d0fe4cf;p=thirdparty%2Fnftables.git netlink_delinearize: Replace some BUG()s by error messages 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 Reviewed-by: Pablo Neira Ayuso --- diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c index 990032f7..14cb8f6c 100644 --- a/src/netlink_delinearize.c +++ b/src/netlink_delinearize.c @@ -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);