]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Fix searching when search query has invalid keywords.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 27 Apr 2017 09:53:18 +0000 (12:53 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Thu, 11 May 2017 10:04:53 +0000 (13:04 +0300)
For example "SEARCH KEYWORD ]" was returning all mails instead of nothing.

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

index cc764cc64b76a0ce24a45b74ca7f9794b4752cb8..3da36f77e5ce960df45ab16ac9255232c2ba8471 100644 (file)
@@ -158,6 +158,11 @@ static int search_arg_match_keywords(struct index_search_context *ctx,
        const unsigned int *keyword_indexes;
        unsigned int i, j, count;
 
+       if (search_kws->count == 0) {
+               /* invalid keyword - never matches */
+               return 0;
+       }
+
        t_array_init(&keyword_indexes_arr, 128);
        mail_index_lookup_keywords(ctx->view, ctx->mail_ctx.seq,
                                   &keyword_indexes_arr);
index 384e76213718cc3bb08a925ae1bd0b2f804909ed..e22e2c8d2e6eabc060e6873a0e29d5c9c1336a0d 100644 (file)
@@ -109,6 +109,8 @@ struct mail_search_arg {
        /* set by mail_search_args_init(): */
        struct {
                struct mail_search_args *search_args;
+               /* Note that initialized keywords may be empty if the keyword
+                  wasn't valid in this mailbox. */
                struct mail_keywords *keywords;
                struct imap_match_glob *mailbox_glob;
        } initialized;