From: Timo Sirainen Date: Mon, 6 Feb 2017 16:34:05 +0000 (+0200) Subject: sdbox: Fix assert-crash on mailbox create race X-Git-Tag: 2.3.0.rc1~2154 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c72fbbe6328ceb0919b5146ecd43817dc294c314;p=thirdparty%2Fdovecot%2Fcore.git sdbox: Fix assert-crash on mailbox create race If another process created the mailbox at the same time, the mailbox_guid wasn't set and opening the mailbox assert-crashed: Panic: file mail-storage.c: line 1744 (mailbox_get_metadata): assertion failed: ((items & MAILBOX_METADATA_GUID) == 0 || !guid_128_is_empty(metadata_r->guid)) --- diff --git a/src/lib-storage/index/dbox-single/sdbox-storage.c b/src/lib-storage/index/dbox-single/sdbox-storage.c index e86e1beb90..1a628d5eda 100644 --- a/src/lib-storage/index/dbox-single/sdbox-storage.c +++ b/src/lib-storage/index/dbox-single/sdbox-storage.c @@ -372,6 +372,32 @@ static void sdbox_mailbox_close(struct mailbox *box) index_storage_mailbox_close(box); } +static int +sdbox_mailbox_create(struct mailbox *box, + const struct mailbox_update *update, bool directory) +{ + struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box; + struct sdbox_index_header hdr; + bool need_resize; + + if (dbox_mailbox_create(box, update, directory) < 0) + return -1; + if (directory || !guid_128_is_empty(mbox->mailbox_guid)) + return 0; + + /* another process just created the mailbox. read the mailbox_guid. */ + if (sdbox_read_header(mbox, &hdr, FALSE, &need_resize) < 0) { + mail_storage_set_critical(box->storage, + "sdbox %s: Failed to read newly created dbox header", + mailbox_get_path(&mbox->box)); + return -1; + } + memcpy(mbox->mailbox_guid, hdr.mailbox_guid, + sizeof(mbox->mailbox_guid)); + i_assert(!guid_128_is_empty(mbox->mailbox_guid)); + return 0; +} + static int sdbox_mailbox_get_metadata(struct mailbox *box, enum mailbox_metadata_items items, @@ -448,7 +474,7 @@ struct mailbox sdbox_mailbox = { sdbox_mailbox_open, sdbox_mailbox_close, index_storage_mailbox_free, - dbox_mailbox_create, + sdbox_mailbox_create, dbox_mailbox_update, index_storage_mailbox_delete, index_storage_mailbox_rename,