From: Timo Sirainen Date: Tue, 3 Dec 2019 21:55:55 +0000 (+0200) Subject: lib-storage: mailbox_get_metadata() - Return cache_fields allocated from data stack X-Git-Tag: 2.3.10~183 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6f8faf0f30f70efc0bdadbe82f1c3d1e0a63f9ac;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: mailbox_get_metadata() - Return cache_fields allocated from data stack 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. --- diff --git a/src/lib-storage/index/index-status.c b/src/lib-storage/index/index-status.c index c7559e7042..1a2fff8aee 100644 --- a/src/lib-storage/index/index-status.c +++ b/src/lib-storage/index/index-status.c @@ -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) { diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index d5b450f218..953aaa2611 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -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; diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index b4528fe033..ded8632aae 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -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;