* [PATCH nft] src: fix always-true assertions
@ 2022-04-26 10:29 Florian Westphal
2022-04-26 10:45 ` Pablo Neira Ayuso
0 siblings, 1 reply; 3+ messages in thread
From: Florian Westphal @ 2022-04-26 10:29 UTC (permalink / raw)
To: netfilter-devel; +Cc: Florian Westphal
assert(1) is a no-op, this should be assert(0). Use BUG() instead.
Add missing CATCHALL to avoid BUG().
Signed-off-by: Florian Westphal <fw@strlen.de>
---
src/evaluate.c | 2 +-
src/intervals.c | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/evaluate.c b/src/evaluate.c
index b5f74d2f5051..1447a4c28aee 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -1499,7 +1499,7 @@ static int interval_set_eval(struct eval_ctx *ctx, struct set *set,
case CMD_GET:
break;
default:
- assert(1);
+ BUG("unhandled op %d\n", ctx->cmd->op);
break;
}
diff --git a/src/intervals.c b/src/intervals.c
index a74238525d8d..85ec59eda36a 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -20,6 +20,7 @@ static void setelem_expr_to_range(struct expr *expr)
assert(expr->etype == EXPR_SET_ELEM);
switch (expr->key->etype) {
+ case EXPR_SET_ELEM_CATCHALL:
case EXPR_RANGE:
break;
case EXPR_PREFIX:
@@ -53,7 +54,7 @@ static void setelem_expr_to_range(struct expr *expr)
expr->key = key;
break;
default:
- assert(1);
+ BUG("unhandled key type %d\n", expr->key->etype);
}
}
@@ -185,7 +186,7 @@ static struct expr *interval_expr_key(struct expr *i)
elem = i;
break;
default:
- assert(1);
+ BUG("unhandled expression type %d\n", i->etype);
return NULL;
}
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH nft] src: fix always-true assertions
2022-04-26 10:29 [PATCH nft] src: fix always-true assertions Florian Westphal
@ 2022-04-26 10:45 ` Pablo Neira Ayuso
2022-04-26 11:22 ` Florian Westphal
0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2022-04-26 10:45 UTC (permalink / raw)
To: Florian Westphal; +Cc: netfilter-devel
On Tue, Apr 26, 2022 at 12:29:35PM +0200, Florian Westphal wrote:
> assert(1) is a no-op, this should be assert(0). Use BUG() instead.
> Add missing CATCHALL to avoid BUG().
LGTM.
So this is fixing a bug with catch-all element, correct?
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
> src/evaluate.c | 2 +-
> src/intervals.c | 5 +++--
> 2 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/src/evaluate.c b/src/evaluate.c
> index b5f74d2f5051..1447a4c28aee 100644
> --- a/src/evaluate.c
> +++ b/src/evaluate.c
> @@ -1499,7 +1499,7 @@ static int interval_set_eval(struct eval_ctx *ctx, struct set *set,
> case CMD_GET:
> break;
> default:
> - assert(1);
> + BUG("unhandled op %d\n", ctx->cmd->op);
> break;
> }
>
> diff --git a/src/intervals.c b/src/intervals.c
> index a74238525d8d..85ec59eda36a 100644
> --- a/src/intervals.c
> +++ b/src/intervals.c
> @@ -20,6 +20,7 @@ static void setelem_expr_to_range(struct expr *expr)
> assert(expr->etype == EXPR_SET_ELEM);
>
> switch (expr->key->etype) {
> + case EXPR_SET_ELEM_CATCHALL:
> case EXPR_RANGE:
> break;
> case EXPR_PREFIX:
> @@ -53,7 +54,7 @@ static void setelem_expr_to_range(struct expr *expr)
> expr->key = key;
> break;
> default:
> - assert(1);
> + BUG("unhandled key type %d\n", expr->key->etype);
> }
> }
>
> @@ -185,7 +186,7 @@ static struct expr *interval_expr_key(struct expr *i)
> elem = i;
> break;
> default:
> - assert(1);
> + BUG("unhandled expression type %d\n", i->etype);
> return NULL;
> }
>
> --
> 2.35.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH nft] src: fix always-true assertions
2022-04-26 10:45 ` Pablo Neira Ayuso
@ 2022-04-26 11:22 ` Florian Westphal
0 siblings, 0 replies; 3+ messages in thread
From: Florian Westphal @ 2022-04-26 11:22 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: Florian Westphal, netfilter-devel
Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> On Tue, Apr 26, 2022 at 12:29:35PM +0200, Florian Westphal wrote:
> > assert(1) is a no-op, this should be assert(0). Use BUG() instead.
> > Add missing CATCHALL to avoid BUG().
>
> LGTM.
>
> So this is fixing a bug with catch-all element, correct?
Not really, the default label is hit, assert(1) does not do anything.
After making the assertion work we need to avoid the 'default' label.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-26 11:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-26 10:29 [PATCH nft] src: fix always-true assertions Florian Westphal
2022-04-26 10:45 ` Pablo Neira Ayuso
2022-04-26 11:22 ` Florian Westphal
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.