From cd337e465bf8bf33d556fc397787d1519d1cef07 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 7 Feb 2017 20:41:41 +0200 Subject: [PATCH] quota: Make sure quota_warning doesn't wrap "quota before" value. This could happen in some race conditions (and with bugs). --- src/plugins/quota/quota.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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, -- 2.47.3