]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: release existing datatype when evaluating unary expression
authorPablo Neira Ayuso <pablo@netfilter.org>
Fri, 28 Feb 2025 14:54:55 +0000 (15:54 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 7 Mar 2025 12:56:46 +0000 (13:56 +0100)
Use __datatype_set() to release the existing datatype before assigning
the new one, otherwise ASAN reports the following memleak:

Direct leak of 104 byte(s) in 1 object(s) allocated from:
    #0 0x7fbc8a2b89cf in __interceptor_malloc ../../../../src/libsa
    #1 0x7fbc898c96c2 in xmalloc src/utils.c:31
    #2 0x7fbc8971a182 in datatype_clone src/datatype.c:1406
    #3 0x7fbc89737c35 in expr_evaluate_unary src/evaluate.c:1366
    #4 0x7fbc89758ae9 in expr_evaluate src/evaluate.c:3057
    #5 0x7fbc89726bd9 in byteorder_conversion src/evaluate.c:243
    #6 0x7fbc89739ff0 in expr_evaluate_bitwise src/evaluate.c:1491
    #7 0x7fbc8973b4f8 in expr_evaluate_binop src/evaluate.c:1600
    #8 0x7fbc89758b01 in expr_evaluate src/evaluate.c:3059
    #9 0x7fbc8975ae0e in stmt_evaluate_arg src/evaluate.c:3198
    #10 0x7fbc8975c51d in stmt_evaluate_payload src/evaluate.c:330

Fixes: faa6908fad60 ("evaluate: clone unary expression datatype to deal with dynamic datatype")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/evaluate.c

index 25c07d90695be7d307c21ab28aa9784f820fe528..f79667bd41ea8cc1e64c8e5f3ede70b5aa6f0620 100644 (file)
@@ -1359,7 +1359,7 @@ static int expr_evaluate_unary(struct eval_ctx *ctx, struct expr **expr)
                BUG("invalid unary operation %u\n", unary->op);
        }
 
-       unary->dtype     = datatype_clone(arg->dtype);
+       __datatype_set(unary, datatype_clone(arg->dtype));
        unary->byteorder = byteorder;
        unary->len       = arg->len;
        return 0;