From 57a8199dcbf88fa9582ef2cc1ee9ec3bcaaad8b1 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Tue, 2 Apr 2019 12:50:16 +0000 Subject: [PATCH] fix trash_append() Prevent a crash when reopening a Mailbox. > How exactly do these changes prevent the crash from occurring? It's all about how mx_mbox_open() handles flags. These four examples are where we have a Mailbox open in 'normal' mode and try to open it again in 'append' mode. 'Append' mode only makes sense for 'mbox' and 'compress', but the flag affects mx_mbox_open(). It causes the function to create a duplicate Mailbox, which is then used and discarded. The original Mailbox is now out of sync. The workaround, simply hides the flag for mx_mbox_open(), but temporarily sets the internal bool append. This means that we work with one Mailbox. --- mx.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mx.c b/mx.c index fac8b4649..220152a0c 100644 --- a/mx.c +++ b/mx.c @@ -491,9 +491,12 @@ static int trash_append(struct Mailbox *m) #endif struct Mailbox *m_trash = mx_path_resolve(C_Trash); - struct Context *ctx_trash = mx_mbox_open(m_trash, MUTT_APPEND); + struct Context *ctx_trash = mx_mbox_open(m_trash, MUTT_OPEN_NO_FLAGS); if (ctx_trash) { + bool old_append = m_trash->append; + m_trash->append = true; + /* continue from initial scan above */ for (int i = first_del; i < m->msg_count; i++) { @@ -502,12 +505,14 @@ static int trash_append(struct Mailbox *m) if (mutt_append_message(ctx_trash->mailbox, m, m->emails[i], MUTT_CM_NO_FLAGS, CH_NO_FLAGS) == -1) { + m_trash->append = old_append; mx_mbox_close(&ctx_trash); return -1; } } } + m_trash->append = old_append; mx_mbox_close(&ctx_trash); } else -- 2.40.0