]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-var-expand: Check that modulo is positive in special case for fn_calculate()
authorAki Tuomi <aki.tuomi@open-xchange.com>
Sun, 22 Mar 2026 18:51:26 +0000 (20:51 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 23 Mar 2026 13:40:28 +0000 (15:40 +0200)
src/lib-var-expand/expansion-filter.c
src/lib-var-expand/test-var-expand.c

index df6bcf0a803fdbb5a261b9c3be92d3500205dcac..9443abd033404294bdd25a43e4167057ccbf72c6 100644 (file)
@@ -151,7 +151,7 @@ static int fn_calculate(const struct var_expand_statement *stmt,
           binary input can be treated as 64 bit unsigned integer
           for modulo operations only. */
        if (state->transfer_binary && oper == VAR_EXPAND_STATEMENT_OPER_MODULO) {
-               if (right < 0) {
+               if (right <= 0) {
                        *error_r = "Binary modulo must be positive integer";
                        return -1;
                }
index 6aa44cbcd5fda5a68c68ffcc055a1549c0dacc39..4a73804f93b93a968e3111fb08d0bec2ca839a3b 100644 (file)
@@ -316,6 +316,7 @@ static void test_var_expand_math(void) {
                { .in = "%{port % 5}", .out = "3", .ret = 0 },
                { .in = "%{port / 0}", .out = "calculate: Division by zero", .ret = -1 },
                { .in = "%{port % 0}", .out = "calculate: Modulo by zero", .ret = -1 },
+               { .in = "%{third | sha256 % 0}", .out = "calculate: Binary modulo must be positive integer", .ret = -1 },
                /* multiple programs, first fails */
                { .in = "%{failure} %{port}", .out = "Unknown variable 'failure'", .ret = -1 },
                /* second fails */