From: Kevin McCarthy Date: Fri, 22 Sep 2017 18:07:27 +0000 (-0700) Subject: Fix imap sync segfault due to inactive headers during an expunge. (closes #3971) X-Git-Tag: neomutt-20171006~35^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=19d96ef857d8773dd16d721608b2547482a579f8;p=neomutt Fix imap sync segfault due to inactive headers during an expunge. (closes #3971) Mutt has several places where it turns off h->active as a hack. For example to avoid FLAG updates, or to exclude from imap_exec_msgset. Unfortunately, when a reopen is allowed and the IMAP_EXPUNGE_PENDING flag becomes set (e.g. a flag update to a modified header), imap_expunge_mailbox() will be called by imap_cmd_finish(). The mx_update_tables() would free and remove these "inactive" headers, despite that an EXPUNGE was not received for them. This would result in memory leaks and segfaults due to dangling pointers in the msn_index and uid_hash. There should probably be a more elegant solution, removing the initial hacks. However, this is causing a segfault, and the best solution right now is to turn active back on for non-expunged messages in imap_expunge_mailbox(). Extra thanks to chdiza, who bravely runs tip and found this issue quickly. --- diff --git a/imap/imap.c b/imap/imap.c index 28cf6b943..f10987a14 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -318,7 +318,26 @@ void imap_expunge_mailbox(struct ImapData *idata) imap_free_header_data((struct ImapHeaderData **) &h->data); } else + { h->index = i; + /* Mutt has several places where it turns off h->active as a + * hack. For example to avoid FLAG updates, or to exclude from + * imap_exec_msgset. + * + * Unfortunately, when a reopen is allowed and the IMAP_EXPUNGE_PENDING + * flag becomes set (e.g. a flag update to a modified header), + * this function will be called by imap_cmd_finish(). + * + * The mx_update_tables() will free and remove these "inactive" headers, + * despite that an EXPUNGE was not received for them. + * This would result in memory leaks and segfaults due to dangling + * pointers in the msn_index and uid_hash. + * + * So this is another hack to work around the hacks. We don't want to + * remove the messages, so make sure active is on. + */ + h->active = true; + } } #ifdef USE_HCACHE