[PATCH nft v5 5/8] evaluate: preserve existing binop properties

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In certain cases, such as evaluating payload statement arguments, we
allocate new binop expressions and set properties such as length,
data-type and byte-order.  When the new expressions are themselves
evaluated, these properties are overridden.  Since the length of
expression is set in all cases, check for this and preserve the length,
data-type and byte-order for bitwise op's and the length for shifts.

Remove a couple of superfluous assignments for a left-shift which were
being correctly overridden.

Signed-off-by: Jeremy Sowden <jeremy@xxxxxxxxxx>
---
 src/evaluate.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/evaluate.c b/src/evaluate.c
index 77781f0ec6de..136b4539e828 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -1301,7 +1301,9 @@ static int expr_evaluate_shift(struct eval_ctx *ctx, struct expr **expr)
 	unsigned int shift = mpz_get_uint32(right->value);
 	unsigned int max_shift_len;
 
-	if (ctx->stmt_len > left->len)
+	if (op->len)
+		max_shift_len = op->len;
+	else if (ctx->stmt_len > left->len)
 		max_shift_len = ctx->stmt_len;
 	else
 		max_shift_len = left->len;
@@ -1335,7 +1337,16 @@ static int expr_evaluate_bitwise(struct eval_ctx *ctx, struct expr **expr)
 	unsigned int max_len;
 	int byteorder;
 
-	if (ctx->stmt_len > left->len) {
+	if (op->len) {
+		max_len = op->len;
+		byteorder = op->byteorder;
+		dtype = op->dtype;
+
+		if (byteorder_conversion(ctx, &op->left, byteorder) < 0)
+			return -1;
+
+		left = op->left;
+	} else if (ctx->stmt_len > left->len) {
 		max_len = ctx->stmt_len;
 		byteorder = BYTEORDER_HOST_ENDIAN;
 		dtype = &integer_type;
@@ -2962,8 +2973,6 @@ static int stmt_evaluate_payload(struct eval_ctx *ctx, struct stmt *stmt)
 
 		lshift = binop_expr_alloc(&payload->location, OP_LSHIFT,
 					  stmt->payload.val, off);
-		lshift->dtype     = payload->dtype;
-		lshift->byteorder = payload->byteorder;
 
 		stmt->payload.val = lshift;
 	}
-- 
2.39.2




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux