]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Don't crash when searching multiple keywords.
authorTimo Sirainen <tss@iki.fi>
Thu, 4 Oct 2012 21:15:01 +0000 (00:15 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 4 Oct 2012 21:15:01 +0000 (00:15 +0300)
Fixed by simply removing the keyword merging code.
mail_search_args_simplify() is called before mail_search_args_init(), so the
keywords are still NULL and merging can't be done. Alternative fix would
have been to add string array to mail_search_arg.value containing the
keywords, but all of this is a pretty unnecessary optimization.

src/lib-storage/mail-search.c

index 5b71ab8a4fbdb537c4fd454eab7894dc8d272791..338789ccc8b888ba8665df599dc19eaa38962855 100644 (file)
@@ -586,48 +586,14 @@ bool mail_search_args_match_mailbox(struct mail_search_args *args,
        return TRUE;
 }
 
-static struct mail_keywords *
-mail_search_keywords_merge(struct mailbox *box,
-                          struct mail_keywords **_kw1,
-                          struct mail_keywords **_kw2)
-{
-       struct mail_keywords *kw1 = *_kw1, *kw2 = *_kw2;
-       struct mail_keywords *new_kw;
-
-       i_assert(kw1->index == kw2->index);
-       T_BEGIN {
-               ARRAY_TYPE(keyword_indexes) new_indexes;
-               unsigned int i, j;
-
-               t_array_init(&new_indexes, kw1->count + kw2->count + 1);
-               array_append(&new_indexes, kw1->idx, kw1->count);
-               for (i = 0; i < kw2->count; i++) {
-                       /* don't add duplicates */
-                       for (j = 0; j < kw1->count; j++) {
-                               if (kw1->idx[j] == kw2->idx[i])
-                                       break;
-                       }
-                       if (j == kw1->count)
-                               array_append(&new_indexes, kw2->idx+i, 1);
-               }
-               new_kw = mailbox_keywords_create_from_indexes(box,
-                                                             &new_indexes);
-       } T_END;
-       mailbox_keywords_unref(_kw1);
-       mailbox_keywords_unref(_kw2);
-       return new_kw;
-}
-
 static void
 mail_search_args_simplify_sub(struct mailbox *box,
                              struct mail_search_arg *args, bool parent_and)
 {
        struct mail_search_arg *sub, *prev = NULL;
        struct mail_search_arg *prev_flags_arg, *prev_not_flags_arg;
-       struct mail_search_arg *prev_kw_arg, *prev_not_kw_arg;
 
        prev_flags_arg = prev_not_flags_arg = NULL;
-       prev_kw_arg = prev_not_kw_arg = NULL;
        while (args != NULL) {
                if (args->match_not && (args->type == SEARCH_SUB ||
                                        args->type == SEARCH_OR)) {
@@ -689,35 +655,6 @@ mail_search_args_simplify_sub(struct mailbox *box,
                        }
                }
 
-               /* merge all keywords arguments */
-               if (args->type == SEARCH_KEYWORDS &&
-                   !args->match_not && parent_and) {
-                       if (prev_kw_arg == NULL)
-                               prev_kw_arg = args;
-                       else {
-                               prev_kw_arg->value.keywords =
-                                       mail_search_keywords_merge(box,
-                                               &prev_kw_arg->value.keywords,
-                                               &args->value.keywords);
-                               prev->next = args->next;
-                               args = args->next;
-                               continue;
-                       }
-               } else if (args->type == SEARCH_KEYWORDS &&
-                          args->match_not && !parent_and) {
-                       if (prev_not_kw_arg == NULL)
-                               prev_not_kw_arg = args;
-                       else {
-                               prev_not_kw_arg->value.keywords =
-                                       mail_search_keywords_merge(box,
-                                              &prev_not_kw_arg->value.keywords,
-                                              &args->value.keywords);
-                               prev->next = args->next;
-                               args = args->next;
-                               continue;
-                       }
-               }
-
                prev = args;
                args = args->next;
        }