]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
sdbox: Fix assert-crash on mailbox create race
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 6 Feb 2017 16:34:05 +0000 (18:34 +0200)
committerGitLab <gitlab@git.dovecot.net>
Wed, 8 Feb 2017 10:36:41 +0000 (12:36 +0200)
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))

src/lib-storage/index/dbox-single/sdbox-storage.c

index e86e1beb9021e2ff0f9573168eceac3562bf2e9a..1a628d5eda61340e68859a3810b88f19ca25c285 100644 (file)
@@ -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,