diff mbox series

[nft,v4,20/32] evaluate: prevent nested byte-order conversions

Message ID 20220404121410.188509-21-jeremy@azazel.net
State Under Review
Delegated to: Pablo Neira
Headers show
Series Extend values assignable to packet marks and payload fields | expand

Commit Message

Jeremy Sowden April 4, 2022, 12:13 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 | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/src/evaluate.c b/src/evaluate.c
index 1b252076e124..3f697eb1dd43 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -144,6 +144,14 @@  static int byteorder_conversion(struct eval_ctx *ctx, struct expr **expr,
 	if ((*expr)->etype == EXPR_CONCAT)
 		return 0;
 
+	/* Remove existing conversion */
+	if ((*expr)->etype == EXPR_UNARY) {
+		struct expr *unary = *expr;
+		*expr = expr_get((*expr)->arg);
+		expr_free(unary);
+		return 0;
+	}
+
 	if (expr_basetype(*expr)->type != TYPE_INTEGER)
 		return expr_error(ctx->msgs, *expr,
 			 	  "Byteorder mismatch: expected %s, got %s",