dovecot-2.2: quota: Avoid crash in quota_root_iter_init() if mai...

dovecot at dovecot.org dovecot at dovecot.org
Mon Sep 28 09:35:20 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/14f670053196
changeset: 19233:14f670053196
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Sep 28 12:33:33 2015 +0300
description:
quota: Avoid crash in quota_root_iter_init() if mailbox has no quota enabled.
This allows quota_get_mail_user_quota() to be called even when quota doesn't
exist. Cleaned up all the code using it to now check for the NULL result.

This fixes a crash in quota_clone plugin.

diffstat:

 src/plugins/quota/quota-storage.c |  13 ++++++-------
 src/plugins/quota/quota.c         |   5 +++++
 2 files changed, 11 insertions(+), 7 deletions(-)

diffs (69 lines):

diff -r 9b2be8702e59 -r 14f670053196 src/plugins/quota/quota-storage.c
--- a/src/plugins/quota/quota-storage.c	Mon Sep 28 12:19:20 2015 +0300
+++ b/src/plugins/quota/quota-storage.c	Mon Sep 28 12:33:33 2015 +0300
@@ -501,7 +501,7 @@
 {
 	struct quota_user *quser = QUOTA_USER_CONTEXT(user);
 
-	return quser->quota;
+	return quser == NULL ? NULL : quser->quota;
 }
 
 static void quota_user_deinit(struct mail_user *user)
@@ -572,11 +572,10 @@
 	struct mail_user *quota_user;
 	bool add;
 
-	if (QUOTA_USER_CONTEXT(list->ns->user) == NULL)
-		return;
-
 	/* see if we have a quota explicitly defined for this namespace */
 	quota = quota_get_mail_user_quota(list->ns->user);
+	if (quota == NULL)
+		return;
 	root = quota_find_root_for_ns(quota, list->ns);
 	if (root != NULL) {
 		/* explicit quota root */
@@ -609,6 +608,7 @@
 		MODULE_CONTEXT_SET(list, quota_mailbox_list_module, qlist);
 
 		quota = quota_get_mail_user_quota(quota_user);
+		i_assert(quota != NULL);
 		quota_add_user_namespace(quota, list->ns);
 	}
 }
@@ -646,10 +646,9 @@
 	struct quota_root *const *roots;
 	unsigned int i, count;
 
-	if (QUOTA_USER_CONTEXT(namespaces->user) == NULL)
+	quota = quota_get_mail_user_quota(namespaces->user);
+	if (quota == NULL)
 		return;
-
-	quota = quota_get_mail_user_quota(namespaces->user);
 	roots = array_get(&quota->roots, &count);
 	for (i = 0; i < count; i++)
 		quota_root_set_namespace(roots[i], namespaces);
diff -r 9b2be8702e59 -r 14f670053196 src/plugins/quota/quota.c
--- a/src/plugins/quota/quota.c	Mon Sep 28 12:19:20 2015 +0300
+++ b/src/plugins/quota/quota.c	Mon Sep 28 12:33:33 2015 +0300
@@ -590,6 +590,9 @@
 	uint64_t value, limit;
 	int ret;
 
+	if (iter->quota == NULL)
+		return NULL;
+
 	roots = array_get(&iter->quota->roots, &count);
 	if (iter->i >= count)
 		return NULL;
@@ -635,6 +638,8 @@
 	unsigned int i, count;
 
 	quota = quota_get_mail_user_quota(user);
+	if (quota == NULL)
+		return NULL;
 	roots = array_get(&quota->roots, &count);
 	for (i = 0; i < count; i++) {
 		if (strcmp(roots[i]->set->name, name) == 0)


More information about the dovecot-cvs mailing list