From 0f3f7325d5c0e3b3e86ebbd3d91c630d1ee88347 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 15 Feb 2017 18:05:14 +0200 Subject: [PATCH] lib-storage: Make sure mailbox undeletion won't go to infinite loop --- src/lib-storage/mail-storage-private.h | 2 ++ src/lib-storage/mail-storage.c | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index 02948733e9..48a39f4168 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -395,6 +395,8 @@ struct mailbox { unsigned int creating:1; /* Mailbox is being deleted */ unsigned int deleting:1; + /* Mailbox is being undeleted */ + unsigned int mailbox_undeleting:1; /* Don't use MAIL_INDEX_SYNC_FLAG_DELETING_INDEX for sync flag */ unsigned int delete_sync_check:1; /* Delete mailbox only if it's empty */ diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 143a581273..eaeae1a358 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -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 -- 2.47.3