Skip to contentSkip to conversation

evaluate: clone unary expression datatype to deal with dynamic datatype

PATCH New Pablo Neira Ayuso 1 participant 1 message Nov 22, 2023 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 evaluate: clone unary expression datatype to deal with dynamic datatype

When allocating a unary expression, clone the datatype to deal with dynamic datatypes.

Fixes 6b01bb9ff798 ("datatype: concat expression only releases dynamically allocated datatype")
---
 src/evaluate.c                                  |  2 +-
 tests/shell/testcases/maps/dumps/vmap_unary.nft | 11 +++++++++++
 tests/shell/testcases/maps/vmap_unary           | 17 +++++++++++++++++
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 tests/shell/testcases/maps/dumps/vmap_unary.nft
 create mode 100755 tests/shell/testcases/maps/vmap_unary
src/evaluate.c +1 -1
index bcf83d804f32..2ead03471102 100644
@@ -1245,7 +1245,7 @@ static int expr_evaluate_unary(struct eval_ctx *ctx, struct expr **expr)
 		BUG("invalid unary operation %u\n", unary->op);
 	}
 
-	unary->dtype	 = arg->dtype;
+	unary->dtype	 = datatype_clone(arg->dtype);
 	unary->byteorder = byteorder;
 	unary->len	 = arg->len;
 	return 0;
tests/shell/testcases/maps/dumps/vmap_unary.nft new file +11 -0
new file mode 100644
index 000000000000..46c538b7910d
@@ -0,0 +1,11 @@
+table ip filter {
+	map ipsec_in {
+		typeof ipsec in reqid . iif : verdict
+		flags interval
+	}
+
+	chain INPUT {
+		type filter hook input priority filter; policy drop;
+		ipsec in reqid . iif vmap @ipsec_in
+	}
+}
tests/shell/testcases/maps/vmap_unary new file +17 -0
new file mode 100755
index 000000000000..4038d1c109ff
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+set -e
+
+RULESET="table ip filter {
+	map ipsec_in {
+		typeof ipsec in reqid . iif : verdict
+		flags interval
+	}
+
+	chain INPUT {
+		type filter hook input priority 0; policy drop
+		ipsec in reqid . iif vmap @ipsec_in
+	}
+}"
+
+$NFT -f - <<< $RULESET
Signature · 1 line
2.30.2