]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: When search parses message headers, deinitialize the parsing properly
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 28 Sep 2021 21:04:29 +0000 (00:04 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 22 Oct 2021 11:18:39 +0000 (14:18 +0300)
index_mail_parse_header() was being called only for the actual headers.
This prevented it from being called with hdr=NULL to indicate that the
parsing is finished and should be deinitialized. Move the
index_mail_parse_header() to be called earlier so it's called also with
hdr=NULL.

Not deinitilizing the parsing could have caused assert-crashes later on in
some situations.

Fixes:
Panic: file index-mail-headers.c: line 667 (index_mail_get_raw_headers): assertion failed: (mail->mail.mail.lookup_abort >= MAIL_LOOKUP_ABORT_NOT_IN_CACHE)
Panic: file ../../../src/lib/array.h: line 244 (array_idx_i): assertion failed: (idx < array->buffer->used / array->element_size)
Panic: file index-mail.c: line 1203 (index_mail_parse_body_finish): assertion failed: (!success)

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

index 929aa4b3fd3ca53d20a5b42de726835bfd238001..c58fa305ac267aff6d2cdde8ce15574a07d4a2f1 100644 (file)
@@ -659,6 +659,9 @@ static void search_header_unmatch(struct mail_search_arg *arg,
 static void search_header(struct message_header_line *hdr,
                          struct search_header_context *ctx)
 {
+       if (ctx->parse_headers)
+               index_mail_parse_header(NULL, hdr, ctx->imail);
+
        if (hdr == NULL) {
                /* end of headers, mark all unknown SEARCH_HEADERs unmatched */
                (void)mail_search_args_foreach(ctx->args, search_header_unmatch,
@@ -669,9 +672,6 @@ static void search_header(struct message_header_line *hdr,
        if (hdr->eoh)
                return;
 
-       if (ctx->parse_headers)
-               index_mail_parse_header(NULL, hdr, ctx->imail);
-
        if (ctx->custom_header || strcasecmp(hdr->name, "Date") == 0) {
                ctx->hdr = hdr;