]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-var-expand: Reduce truncated buffer size only if necessary
authorKarl Fleischmann <karl.fleischmann@open-xchange.com>
Thu, 19 Mar 2026 10:53:22 +0000 (11:53 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 19 Mar 2026 16:01:22 +0000 (16:01 +0000)
src/lib-var-expand/expansion-filter.c
src/lib-var-expand/test-var-expand.c

index 53cf149034dbebccea67c5866ffd53d9c84f6342..df6bcf0a803fdbb5a261b9c3be92d3500205dcac 100644 (file)
@@ -634,7 +634,7 @@ static int fn_truncate(const struct var_expand_statement *stmt,
 
        if (bits)
                buffer_truncate_rshift_bits(new_value, len);
-       else
+       else if (len < state->transfer->used)
                buffer_set_used_size(new_value, len);
 
        var_expand_state_set_transfer_data(state, new_value->data, new_value->used);
index b2292f8d1f0843a27df7cdb7ad9e3e75fbbb733a..0ca8ff7a7c6ee52a8b5af4d034690811402689bc 100644 (file)
@@ -198,7 +198,9 @@ static void test_var_expand_builtin_filters(void) {
                { .in = "%{literal('<<?""?""?>>') | base64(url=1)}", .out = "PDw_Pz8-Pg==", .ret = 0 },
                { .in = "%{literal('<<?""?""?>>') | base64(pad=0,url=1)}", .out = "PDw_Pz8-Pg", .ret = 0 },
                /* truncate */
-               { .in = "%{first | truncate(3)}", .out = "hel", .ret = 0 },
+               { .in = "%{first | truncate(4)}", .out = "hell", .ret = 0 },
+               { .in = "%{first | truncate(5)}", .out = "hello", .ret = 0 },
+               { .in = "%{first | truncate(6)}", .out = "hello", .ret = 0 },
                { .in = "%{first | truncate(three)}", .out = "hel", .ret = 0 },
                { .in = "%{first | truncate(bits=7)}", .out = "4", .ret = 0 },
                { .in = "%{truncate}", .out = "truncate: Missing parameter", .ret = -1 },