From: Timo Sirainen Date: Sat, 17 Feb 2018 21:26:55 +0000 (+0200) Subject: mbox: Fix creating mailbox when mailbox_update struct is given without uidvalidity X-Git-Tag: 2.3.9~2200 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53a5b5d2283d33561253f5ccf5dae0e9be0fb103;p=thirdparty%2Fdovecot%2Fcore.git mbox: Fix creating mailbox when mailbox_update struct is given without uidvalidity 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) --- diff --git a/src/lib-storage/index/mbox/mbox-sync.c b/src/lib-storage/index/mbox/mbox-sync.c index 61140794e4..ef189d300e 100644 --- a/src/lib-storage/index/mbox/mbox-sync.c +++ b/src/lib-storage/index/mbox/mbox-sync.c @@ -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; } }