From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nft 3/3] evaluate: do not crash if dynamic set has no statements
Date: Wed, 3 Feb 2021 19:42:27 +0100 [thread overview]
Message-ID: <20210203184227.32208-3-fw@strlen.de> (raw)
In-Reply-To: <20210203184227.32208-1-fw@strlen.de>
list_first_entry() returns garbage when the list is empty.
There is no need to run the following loop if we have no statements,
so just return 0.
Signed-off-by: Florian Westphal <fw@strlen.de>
---
src/evaluate.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/evaluate.c b/src/evaluate.c
index 0b251ab5554c..2ddbde0a370f 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -1363,10 +1363,12 @@ static int __expr_evaluate_set_elem(struct eval_ctx *ctx, struct expr *elem)
"number of statements mismatch, set expects %d "
"but element has %d", num_set_exprs,
num_elem_exprs);
- } else if (num_set_exprs == 0 && !(set->flags & NFT_SET_EVAL)) {
- return expr_error(ctx->msgs, elem,
- "missing statements in %s definition",
- set_is_map(set->flags) ? "map" : "set");
+ } else if (num_set_exprs == 0) {
+ if (!(set->flags & NFT_SET_EVAL))
+ return expr_error(ctx->msgs, elem,
+ "missing statements in %s definition",
+ set_is_map(set->flags) ? "map" : "set");
+ return 0;
}
set_stmt = list_first_entry(&set->stmt_list, struct stmt, list);
--
2.26.2
prev parent reply other threads:[~2021-02-03 18:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-03 18:41 [PATCH nft 0/3] evaluate: fix crash on empty set restore Florian Westphal
2021-02-03 18:42 ` [PATCH nft 1/3] testcases: move two dump files to correct location Florian Westphal
2021-02-03 18:42 ` [PATCH nft 2/3] tests: add empty dynamic set Florian Westphal
2021-02-03 18:42 ` Florian Westphal [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210203184227.32208-3-fw@strlen.de \
--to=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).