]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: mailbox_get_metadata() - Return cache_fields allocated from data stack
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 3 Dec 2019 21:55:55 +0000 (23:55 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Mon, 16 Dec 2019 09:30:37 +0000 (09:30 +0000)
Using mailbox.metacache_pool breaks if it's called multiple times for the
same mailbox and the old results are still used. This happened in
index_copy_cache_fields() when copying mails within the same mailbox. In
some situations this could have caused a crash.

src/lib-storage/index/index-status.c
src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.c

index c7559e70429420076e3e10384402d64515617890..1a2fff8aee9af7dc41438d45d0dca0bc2ebdc045 100644 (file)
@@ -199,17 +199,11 @@ get_metadata_cache_fields(struct mailbox *box,
        struct mailbox_cache_field *cf;
        unsigned int i, count;
 
-       if (box->metadata_pool == NULL) {
-               box->metadata_pool =
-                       pool_alloconly_create("mailbox metadata", 1024*3);
-       }
-
        fields = mail_cache_register_get_list(box->cache,
-                                             box->metadata_pool, &count);
+                                             pool_datastack_create(), &count);
 
-       cache_fields = p_new(box->metadata_pool,
-                            ARRAY_TYPE(mailbox_cache_field), 1);
-       p_array_init(cache_fields, box->metadata_pool, count);
+       cache_fields = t_new(ARRAY_TYPE(mailbox_cache_field), 1);
+       t_array_init(cache_fields, count);
        for (i = 0; i < count; i++) {
                dec = fields[i].decision & ~MAIL_CACHE_DECISION_FORCED;
                if (dec != MAIL_CACHE_DECISION_NO) {
index d5b450f2180274677269132b1dbfdc5e39c81ff0..953aaa26113e060c0c078b642e87ebeaf2c1b117 100644 (file)
@@ -358,7 +358,7 @@ struct mailbox {
        /* virtual mailboxes: */
        const struct virtual_mailbox_vfuncs *virtual_vfuncs;
 /* private: */
-       pool_t pool, metadata_pool;
+       pool_t pool;
        /* Linked list of all mailboxes in this storage */
        struct mailbox *prev, *next;
 
index b4528fe033c52320795254ff4c8aa38a2b473a06..ded8632aae8ce89031739be8da2f36698b1099dd 100644 (file)
@@ -1641,7 +1641,6 @@ void mailbox_free(struct mailbox **_box)
 
        DLLIST_REMOVE(&box->storage->mailboxes, box);
        mail_storage_obj_unref(box->storage);
-       pool_unref(&box->metadata_pool);
        pool_unref(&box->pool);
 }
 
@@ -2134,9 +2133,6 @@ int mailbox_get_metadata(struct mailbox *box, enum mailbox_metadata_items items,
        if (mailbox_verify_existing_name(box) < 0)
                return -1;
 
-       if (box->metadata_pool != NULL)
-               p_clear(box->metadata_pool);
-
        if (box->v.get_metadata(box, items, metadata_r) < 0)
                return -1;