From: Timo Sirainen Date: Mon, 28 Sep 2015 09:33:33 +0000 (+0300) Subject: quota: Avoid crash in quota_root_iter_init() if mailbox has no quota enabled. X-Git-Tag: 2.2.19.rc2~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=169b679209f7b3e97888704ad3693c709265ef24;p=thirdparty%2Fdovecot%2Fcore.git 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. --- diff --git a/src/plugins/quota/quota-storage.c b/src/plugins/quota/quota-storage.c index fae7165080..e1350fc0b5 100644 --- a/src/plugins/quota/quota-storage.c +++ b/src/plugins/quota/quota-storage.c @@ -501,7 +501,7 @@ struct quota *quota_get_mail_user_quota(struct mail_user *user) { 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 @@ void quota_mailbox_list_created(struct mailbox_list *list) 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 @@ void quota_mailbox_list_created(struct mailbox_list *list) 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 @@ void quota_mail_namespaces_created(struct mail_namespace *namespaces) struct quota_root *const *roots; unsigned int i, count; - if (QUOTA_USER_CONTEXT(namespaces->user) == NULL) - return; - quota = quota_get_mail_user_quota(namespaces->user); + if (quota == NULL) + return; roots = array_get("a->roots, &count); for (i = 0; i < count; i++) quota_root_set_namespace(roots[i], namespaces); diff --git a/src/plugins/quota/quota.c b/src/plugins/quota/quota.c index dd3617fb9d..4d4c721f76 100644 --- a/src/plugins/quota/quota.c +++ b/src/plugins/quota/quota.c @@ -590,6 +590,9 @@ struct quota_root *quota_root_iter_next(struct quota_root_iter *iter) 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 @@ struct quota_root *quota_root_lookup(struct mail_user *user, const char *name) unsigned int i, count; quota = quota_get_mail_user_quota(user); + if (quota == NULL) + return NULL; roots = array_get("a->roots, &count); for (i = 0; i < count; i++) { if (strcmp(roots[i]->set->name, name) == 0)