]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fts: Avoid expanding mail_search_args multiple times (for optimization & crash-avoidance)
authorTimo Sirainen <tss@iki.fi>
Mon, 15 Jun 2015 21:29:07 +0000 (00:29 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 15 Jun 2015 21:29:07 +0000 (00:29 +0300)
Primarily this fixes the crash:

index-search-result.c: line 132 (index_search_result_update_flags):
assertion failed: (result->search_args->args == &search_arg)

It could be triggered by:
a search return (update) body body seen
b store 1 +flags \seen
c store 1 -flags \seen

src/lib-storage/mail-search.h
src/plugins/fts/fts-search-args.c

index 4f4d023c45763d23440c696c4f02173b298b0308..90f0dc680a5f3415aef53b9421fc9aeab8e63d14 100644 (file)
@@ -115,6 +115,9 @@ struct mail_search_args {
        /* Stop mail_search_next() when finding a non-matching mail.
           (Could be useful when wanting to find only the oldest mails.) */
        unsigned int stop_on_nonmatch:1;
+       /* fts plugin has already expanded the search args - no need to do
+          it again. */
+       unsigned int fts_expanded:1;
 };
 
 #define ARG_SET_RESULT(arg, res) \
index afd36b1c0f8145d8e75e98ef361e74f0a0ad1a9d..1de11380f44aca6e0c40758db3a4680d82b5a122 100644 (file)
@@ -185,6 +185,13 @@ int fts_search_args_expand(struct fts_backend *backend,
 {
        struct mail_search_arg *args_dup, *orig_args = args->args;
 
+       /* don't keep re-expanding every time the search args are used.
+          this is especially important to avoid an assert-crash in
+          index_search_result_update_flags(). */
+       if (args->fts_expanded)
+               return 0;
+       args->fts_expanded = TRUE;
+
        /* duplicate the args, so if expansion fails we haven't changed
           anything */
        args_dup = mail_search_arg_dup(args->pool, args->args);