From 4ac2cd199fbae8f52d43db7c817527ba1c5dedaa Mon Sep 17 00:00:00 2001 From: Jeremy Sowden Date: Tue, 3 Mar 2020 09:48:29 +0000 Subject: evaluate: don't evaluate payloads twice. Payload munging means that evaluation of payload expressions may not be idempotent. Add a flag to prevent them from being evaluated more than once. Signed-off-by: Jeremy Sowden Signed-off-by: Florian Westphal --- include/expression.h | 1 + src/evaluate.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/expression.h b/include/expression.h index 62fbbbb5..87c39e5d 100644 --- a/include/expression.h +++ b/include/expression.h @@ -300,6 +300,7 @@ struct expr { enum proto_bases base; unsigned int offset; bool is_raw; + bool evaluated; } payload; struct { /* EXPR_EXTHDR */ diff --git a/src/evaluate.c b/src/evaluate.c index e2eff235..a169e41b 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -736,6 +736,9 @@ static int expr_evaluate_payload(struct eval_ctx *ctx, struct expr **exprp) { struct expr *expr = *exprp; + if (expr->payload.evaluated) + return 0; + if (__expr_evaluate_payload(ctx, expr) < 0) return -1; @@ -745,6 +748,8 @@ static int expr_evaluate_payload(struct eval_ctx *ctx, struct expr **exprp) if (payload_needs_adjustment(expr)) expr_evaluate_bits(ctx, exprp); + expr->payload.evaluated = true; + return 0; } -- cgit v1.2.3