]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Make sure mailbox undeletion won't go to infinite loop
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 15 Feb 2017 16:05:14 +0000 (18:05 +0200)
committerGitLab <gitlab@git.dovecot.net>
Thu, 16 Feb 2017 10:38:36 +0000 (12:38 +0200)
src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.c

index db01656111893ae96bb42bd9b1cdc218f2d4b163..380778bb0f27440ea2f3c79336bdb21a38d1441b 100644 (file)
@@ -396,6 +396,8 @@ struct mailbox {
        bool creating:1;
        /* Mailbox is being deleted */
        bool deleting:1;
+       /* Mailbox is being undeleted */
+       bool mailbox_undeleting:1;
        /* Don't use MAIL_INDEX_SYNC_FLAG_DELETING_INDEX for sync flag */
        bool delete_sync_check:1;
        /* Delete mailbox only if it's empty */
index 143a581273568a93e8faa017b995a526d9f378fb..eaeae1a3582d7d6fc8465f502a28d98911d3d871 100644 (file)
@@ -1136,6 +1136,8 @@ static bool mailbox_try_undelete(struct mailbox *box)
 {
        time_t mtime;
 
+       i_assert(!box->mailbox_undeleting);
+
        if ((box->flags & MAILBOX_FLAG_READONLY) != 0) {
                /* most importantly we don't do this because we want to avoid
                   a loop: mdbox storage rebuild -> mailbox_open() ->
@@ -1148,7 +1150,10 @@ static bool mailbox_try_undelete(struct mailbox *box)
        if (mtime + MAILBOX_DELETE_RETRY_SECS > time(NULL))
                return FALSE;
 
-       if (mailbox_mark_index_deleted(box, FALSE) < 0)
+       box->mailbox_undeleting = TRUE;
+       int ret = mailbox_mark_index_deleted(box, FALSE);
+       box->mailbox_undeleting = FALSE;
+       if (ret < 0)
                return FALSE;
        box->mailbox_deleted = FALSE;
        return TRUE;
@@ -1165,7 +1170,7 @@ int mailbox_open(struct mailbox *box)
        }
 
        if (mailbox_open_full(box, NULL) < 0) {
-               if (!box->mailbox_deleted)
+               if (!box->mailbox_deleted || box->mailbox_undeleting)
                        return -1;
 
                /* mailbox has been marked as deleted. if this deletion