]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quota: Make sure quota_warning doesn't wrap "quota before" value.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 7 Feb 2017 18:41:41 +0000 (20:41 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 7 Feb 2017 18:43:50 +0000 (20:43 +0200)
This could happen in some race conditions (and with bugs).

src/plugins/quota/quota.c

index 143783162cc7d22100b1667256b7c08214a6d9a9..0fd66ee2b3f5a1671326d470b65df1fbd810bfde 100644 (file)
@@ -951,8 +951,15 @@ static void quota_warnings_execute(struct quota_transaction_context *ctx,
                               &count_current, &count_limit) < 0)
                return;
 
-       bytes_before = bytes_current - ctx->bytes_used;
-       count_before = count_current - ctx->count_used;
+       if (ctx->bytes_used > 0 && bytes_current < (uint64_t)ctx->bytes_used)
+               bytes_before = 0;
+       else
+               bytes_before = 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;
        for (i = 0; i < count; i++) {
                if (quota_warning_match(&warnings[i],
                                        bytes_before, bytes_current,