changeset 21505:6c88e7e55768

quota: Make sure quota_warning doesn't wrap "quota before" value. This could happen in some race conditions (and with bugs).
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Tue, 07 Feb 2017 20:41:41 +0200
parents ee051f0429b2
children 4e84b0d61d49
files src/plugins/quota/quota.c
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/quota/quota.c	Tue Feb 07 18:26:50 2017 +0200
+++ b/src/plugins/quota/quota.c	Tue Feb 07 20:41:41 2017 +0200
@@ -946,8 +946,15 @@
 			       &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,