Skip to contentSkip to conversation

evaluate: error out if basetypes are different

PATCH New Florian Westphal 1 participant 1 message Dec 4, 2023 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 evaluate: error out if basetypes are different

prefer
binop_with_different_basetype_assert:3:29-35: Error: Binary operation (<<) with different base types (string vs integer) is not supported oifname set ip9dscp << 26 | 0x10

            ^^^^^^^~~~~~~

to assertion failure.

---
 src/evaluate.c                                             | 7 +++++--
 .../bogons/nft-f/binop_with_different_basetype_assert      | 5 +++++
 2 files changed, 10 insertions(+), 2 deletions(-)
 create mode 100644 tests/shell/testcases/bogons/nft-f/binop_with_different_basetype_assert
src/evaluate.c +5 -2
index b6670254b9fd..51ae276aac6a 100644
@@ -1451,8 +1451,11 @@ static int expr_evaluate_binop(struct eval_ctx *ctx, struct expr **expr)
 					 "for %s expressions",
 					 sym, expr_name(right));
 
-	/* The grammar guarantees this */
-	assert(datatype_equal(expr_basetype(left), expr_basetype(right)));
+	if (!datatype_equal(expr_basetype(left), expr_basetype(right)))
+		return expr_binary_error(ctx->msgs, left, op,
+					 "Binary operation (%s) with different base types "
+					 "(%s vs %s) is not supported",
+					 sym, expr_basetype(left)->name, expr_basetype(right)->name);
 
 	switch (op->op) {
 	case OP_LSHIFT:
tests/shell/testcases/bogons/nft-f/binop_with_different_basetype_assert new file +5 -0
new file mode 100644
index 000000000000..e84360088e99
@@ -0,0 +1,5 @@
+table ip t {
+        chain c {
+                oifname set ip9dscp << 26 | 0x10
+        }
+}
Signature · 1 line
2.41.0