]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mbox: Fix creating mailbox when mailbox_update struct is given without uidvalidity
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sat, 17 Feb 2018 21:26:55 +0000 (23:26 +0200)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Thu, 1 Mar 2018 11:47:10 +0000 (13:47 +0200)
This especially fixes a crash when creating mboxes with LAYOUT=index:

Panic: file mbox-sync.c: line 1241 (mbox_write_pseudo): assertion failed: (uid_validity != 0)

src/lib-storage/index/mbox/mbox-sync.c

index 61140794e48f4c66dbce6fc40f2221d0092a7779..ef189d300ecd2569614829edebade6788727837b 100644 (file)
@@ -1219,7 +1219,7 @@ static int mbox_sync_loop(struct mbox_sync_context *sync_ctx,
        return 1;
 }
 
-static int mbox_write_pseudo(struct mbox_sync_context *sync_ctx)
+static int mbox_write_pseudo(struct mbox_sync_context *sync_ctx, bool force)
 {
        string_t *str;
        unsigned int uid_validity;
@@ -1229,11 +1229,18 @@ static int mbox_write_pseudo(struct mbox_sync_context *sync_ctx)
        if (sync_ctx->mbox->sync_hdr_update != NULL) {
                const struct mailbox_update *update =
                        sync_ctx->mbox->sync_hdr_update;
+               bool change = FALSE;
 
-               if (update->uid_validity != 0)
+               if (update->uid_validity != 0) {
                        sync_ctx->base_uid_validity = update->uid_validity;
-               if (update->min_next_uid != 0)
+                       change = TRUE;
+               }
+               if (update->min_next_uid != 0) {
                        sync_ctx->base_uid_last = update->min_next_uid-1;
+                       change = TRUE;
+               }
+               if (!change && !force)
+                       return 0;
        }
 
        uid_validity = sync_ctx->base_uid_validity != 0 ?
@@ -1401,7 +1408,7 @@ static int mbox_sync_handle_eof_updates(struct mbox_sync_context *sync_ctx,
                }
 
                if (offset == 0) {
-                       if (mbox_write_pseudo(sync_ctx) < 0)
+                       if (mbox_write_pseudo(sync_ctx, TRUE) < 0)
                                return -1;
                }
 
@@ -1409,7 +1416,7 @@ static int mbox_sync_handle_eof_updates(struct mbox_sync_context *sync_ctx,
                mbox_sync_file_updated(sync_ctx, FALSE);
        } else {
                if (file_size == 0 && sync_ctx->mbox->sync_hdr_update != NULL) {
-                       if (mbox_write_pseudo(sync_ctx) < 0)
+                       if (mbox_write_pseudo(sync_ctx, FALSE) < 0)
                                return -1;
                }
        }