]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: fix crash when generating reject statement error
authorFlorian Westphal <fw@strlen.de>
Mon, 31 Mar 2025 12:43:34 +0000 (14:43 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 29 Jul 2025 00:38:27 +0000 (02:38 +0200)
commit 9b7346d1eac2eb90a2baf589affafec5b1a033b6 upstream.

After patch, this gets rejected with:
internal:0:0-0: Error: conflicting protocols specified: ip vs ip6

Without patch, we crash with a NULL dereference: we cannot use
reject.expr->location unconditionally.

Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/evaluate.c

index 4fca39bef68f0ddb49d0ee4d425e7cb91de9c7f0..fac1ea169c61f03528f1a28a9826d28d90faff26 100644 (file)
@@ -3514,6 +3514,18 @@ static int stmt_evaluate_reject_bridge(struct eval_ctx *ctx, struct stmt *stmt,
        return 0;
 }
 
+static int stmt_reject_error(struct eval_ctx *ctx,
+                            const struct stmt *stmt,
+                            const char *msg)
+{
+       struct expr *e = stmt->reject.expr;
+
+       if (e)
+               return stmt_binary_error(ctx, e, stmt, "%s", msg);
+
+       return stmt_error(ctx, stmt, "%s", msg);
+}
+
 static int stmt_evaluate_reject_family(struct eval_ctx *ctx, struct stmt *stmt,
                                       struct expr *expr)
 {
@@ -3528,12 +3540,12 @@ static int stmt_evaluate_reject_family(struct eval_ctx *ctx, struct stmt *stmt,
                                return -1;
                        break;
                case NFT_REJECT_ICMPX_UNREACH:
-                       return stmt_binary_error(ctx, stmt->reject.expr, stmt,
+                       return stmt_reject_error(ctx, stmt,
                                   "abstracted ICMP unreachable not supported");
                case NFT_REJECT_ICMP_UNREACH:
                        if (stmt->reject.family == ctx->pctx.family)
                                break;
-                       return stmt_binary_error(ctx, stmt->reject.expr, stmt,
+                       return stmt_reject_error(ctx, stmt,
                                  "conflicting protocols specified: ip vs ip6");
                }
                break;