]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Fix potential assert-crash when adding missing attachment flags
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 30 Nov 2020 18:37:46 +0000 (20:37 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 4 Dec 2020 11:13:22 +0000 (13:13 +0200)
This happened only in a rather special condition. Added unit test to
reproduce it.

Fixes:
Panic: file index-mail-headers.c: line 298 (index_mail_parse_header): assertion failed: (part != NULL)

src/lib-storage/index/index-mail.c

index 61e6bfb3d85ba35966420a30d1d670d045f96f40..a3629429108b47b04acec27eac327f528e5301f5 100644 (file)
@@ -1412,11 +1412,18 @@ static int index_mail_parse_bodystructure(struct index_mail *mail,
                        /* we haven't parsed the header yet */
                        const char *reason =
                                index_mail_cache_reason(&mail->mail.mail, "bodystructure");
+                       bool orig_bodystructure_header =
+                               data->save_bodystructure_header;
+                       bool orig_bodystructure_body =
+                               data->save_bodystructure_body;
                        data->save_bodystructure_header = TRUE;
                        data->save_bodystructure_body = TRUE;
                        (void)get_cached_parts(mail);
                        if (index_mail_parse_headers(mail, NULL, reason) < 0) {
-                               data->save_bodystructure_header = TRUE;
+                               data->save_bodystructure_header =
+                                       orig_bodystructure_header;
+                               data->save_bodystructure_body =
+                                       orig_bodystructure_body;
                                return -1;
                        }
                        i_assert(data->parser_ctx != NULL);