diff mbox series

[nft,v5,4/8] evaluate: prevent nested byte-order conversions

Message ID 20230528140058.1218669-5-jeremy@azazel.net
State Under Review
Headers show
Series Bitwise boolean operations with variable RHS operands | expand

Commit Message

Jeremy Sowden May 28, 2023, 2 p.m. UTC
There is a an assertion in `expr_evaluate_unary` that checks that the
operand of the unary operation is not itself a unary expression.  Add a
check to `byteorder_conversion` to ensure that this is the case by
removing an existing unary operation, rather than adding a second one.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 src/evaluate.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/src/evaluate.c b/src/evaluate.c
index 17a437bd6530..77781f0ec6de 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -195,7 +195,12 @@  static int byteorder_conversion(struct eval_ctx *ctx, struct expr **expr,
 
 	if (expr_is_constant(*expr) || div_round_up((*expr)->len, BITS_PER_BYTE) < 2)
 		(*expr)->byteorder = byteorder;
-	else {
+	else if ((*expr)->etype == EXPR_UNARY) {
+		/* Remove existing conversion */
+		struct expr *unary = *expr;
+		*expr = expr_get((*expr)->arg);
+		expr_free(unary);
+	} else {
 		op = byteorder_conversion_op(*expr, byteorder);
 		*expr = unary_expr_alloc(&(*expr)->location, op, *expr);
 		if (expr_evaluate(ctx, expr) < 0)