]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quota: Avoid implicit integer conversion to unsigned in quota calculation
authorAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 22 Oct 2020 17:21:41 +0000 (20:21 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 23 Oct 2020 09:52:52 +0000 (09:52 +0000)
Deducting negative number from unsigned integer causes
signed integer conversion to unsigned int, which results a
too large positive number. Do calculations using int64 instead.

This did not cause any visible problems, found by
clang integer sanitization.

src/plugins/quota/quota.c

index 1457ffe654cb52f371a054f8acbe90421de096c0..ef58e71838c7af36e951eac94aee4d8205da41b7 100644 (file)
@@ -1121,12 +1121,12 @@ static void quota_warnings_execute(struct quota_transaction_context *ctx,
        if (ctx->bytes_used > 0 && bytes_current < (uint64_t)ctx->bytes_used)
                bytes_before = 0;
        else
-               bytes_before = bytes_current - ctx->bytes_used;
+               bytes_before = (int64_t)bytes_current - ctx->bytes_used;
 
        if (ctx->count_used > 0 && count_current < (uint64_t)ctx->count_used)
                count_before = 0;
        else
-               count_before = count_current - ctx->count_used;
+               count_before = (int64_t)count_current - ctx->count_used;
        for (i = 0; i < count; i++) {
                if (quota_warning_match(&warnings[i],
                                        bytes_before, bytes_current,