Skip to contentSkip to conversation

evaluate: reject set definition with no key

PATCH New Pablo Neira Ayuso 1 participant 1 message Dec 6, 2023 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH v2 1/1 evaluate: reject set definition with no key

tests/shell/testcases/bogons/nft-f/set_definition_with_no_key_assert

 BUG: unhandled key type 2
 nft: src/intervals.c:59: setelem_expr_to_range: Assertion `0' failed.

This patch adds a new unit tests/shell courtesy of Florian Westphal.

Fixes 3975430b12d9 ("src: expand table command before evaluation")

---
v2: I realize there is a type const char * already around that can be use
to print either "set" or "map", reuse it.

 src/evaluate.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
src/evaluate.c +6 -2
index cf5f32c144d3..5021ae80bbfa 100644
@@ -4693,6 +4693,12 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set)
 	struct stmt *stmt;
 	const char *type;
 
+	type = set_is_map(set->flags) ? "map" : "set";
+
+	if (set->key == NULL)
+		return set_error(ctx, set, "%s definition does not specify key",
+				 type);
+
 	if (!set_is_anonymous(set->flags)) {
 		table = table_cache_find(&ctx->nft->cache.table_cache,
 					 set->handle.table.name,
@@ -4716,8 +4722,6 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set)
 	if (!(set->flags & NFT_SET_INTERVAL) && set->automerge)
 		return set_error(ctx, set, "auto-merge only works with interval sets");
 
-	type = set_is_map(set->flags) ? "map" : "set";
-
 	if (set->key == NULL)
 		return set_error(ctx, set, "%s definition does not specify key",
 				 type);
Signature · 1 line
2.30.2