From fc2f5c4418283dbfc2e008bc4268e9d3b6f313ba Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Mon, 1 Aug 2016 17:11:41 +0200 Subject: evaluate: add small helper to check if payload expr needs binop adjustment kernel can only deal with byte-sized and byte-aligned payload expressions. If the payload expression doesn't fit this requirement userspace has to add explicit binop masks to remove the unwanted part(s). Suggested-by: Pablo Neira Ayuso Signed-off-by: Florian Westphal --- src/evaluate.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/evaluate.c') diff --git a/src/evaluate.c b/src/evaluate.c index 8116735d..7962e9e4 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -575,6 +575,12 @@ static int __expr_evaluate_payload(struct eval_ctx *ctx, struct expr *expr) return 0; } +static bool payload_needs_adjustment(const struct expr *expr) +{ + return expr->payload.offset % BITS_PER_BYTE != 0 || + expr->len % BITS_PER_BYTE != 0; +} + static int expr_evaluate_payload(struct eval_ctx *ctx, struct expr **exprp) { struct expr *expr = *exprp; @@ -585,8 +591,7 @@ static int expr_evaluate_payload(struct eval_ctx *ctx, struct expr **exprp) if (expr_evaluate_primary(ctx, exprp) < 0) return -1; - if (expr->payload.offset % BITS_PER_BYTE != 0 || - expr->len % BITS_PER_BYTE != 0) + if (payload_needs_adjustment(expr)) expr_evaluate_bits(ctx, exprp); return 0; -- cgit v1.2.3