]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quota: Avoid crash in quota_root_iter_init() if mailbox has no quota enabled.
authorTimo Sirainen <tss@iki.fi>
Mon, 28 Sep 2015 09:33:33 +0000 (12:33 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 28 Sep 2015 09:33:33 +0000 (12:33 +0300)
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.

src/plugins/quota/quota-storage.c
src/plugins/quota/quota.c

index fae7165080e6542ad04d73063d4654e2714131ee..e1350fc0b55ca873597b54957d7c87986fb0bdaf 100644 (file)
@@ -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(&quota->roots, &count);
        for (i = 0; i < count; i++)
                quota_root_set_namespace(roots[i], namespaces);
index dd3617fb9dcb1c90f7dcfe368f7700d41a056123..4d4c721f76e139eeeb6a404909b2541193d02ebd 100644 (file)
@@ -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(&quota->roots, &count);
        for (i = 0; i < count; i++) {
                if (strcmp(roots[i]->set->name, name) == 0)