From: Timo Sirainen Date: Tue, 7 Feb 2017 18:41:41 +0000 (+0200) Subject: quota: Make sure quota_warning doesn't wrap "quota before" value. X-Git-Tag: 2.3.0.rc1~2156 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd337e465bf8bf33d556fc397787d1519d1cef07;p=thirdparty%2Fdovecot%2Fcore.git quota: Make sure quota_warning doesn't wrap "quota before" value. This could happen in some race conditions (and with bugs). --- diff --git a/src/plugins/quota/quota.c b/src/plugins/quota/quota.c index 143783162c..0fd66ee2b3 100644 --- a/src/plugins/quota/quota.c +++ b/src/plugins/quota/quota.c @@ -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,