From: Timo Sirainen Date: Tue, 28 Sep 2021 21:04:29 +0000 (+0300) Subject: lib-storage: When search parses message headers, deinitialize the parsing properly X-Git-Tag: 2.3.17~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=720e1be3cb7a1ea749dab98d47c9e47c71d24498;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: When search parses message headers, deinitialize the parsing properly 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) --- diff --git a/src/lib-storage/index/index-search.c b/src/lib-storage/index/index-search.c index 929aa4b3fd..c58fa305ac 100644 --- a/src/lib-storage/index/index-search.c +++ b/src/lib-storage/index/index-search.c @@ -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;