lib-storage: Don't crash when searching multiple keywords.
authorTimo Sirainen <tss@iki.fi>
Fri Oct 05 00:15:01 2012 +0300 (18 months ago)
changeset 147550306792cc843
parent 14754 28be06dbd65e
child 14756 d96313048f17
lib-storage: Don't crash when searching multiple keywords.
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
     1.1 --- a/src/lib-storage/mail-search.c	Wed Oct 03 05:43:27 2012 +0300
     1.2 +++ b/src/lib-storage/mail-search.c	Fri Oct 05 00:15:01 2012 +0300
     1.3 @@ -586,48 +586,14 @@
     1.4  	return TRUE;
     1.5  }
     1.6  
     1.7 -static struct mail_keywords *
     1.8 -mail_search_keywords_merge(struct mailbox *box,
     1.9 -			   struct mail_keywords **_kw1,
    1.10 -			   struct mail_keywords **_kw2)
    1.11 -{
    1.12 -	struct mail_keywords *kw1 = *_kw1, *kw2 = *_kw2;
    1.13 -	struct mail_keywords *new_kw;
    1.14 -
    1.15 -	i_assert(kw1->index == kw2->index);
    1.16 -	T_BEGIN {
    1.17 -		ARRAY_TYPE(keyword_indexes) new_indexes;
    1.18 -		unsigned int i, j;
    1.19 -
    1.20 -		t_array_init(&new_indexes, kw1->count + kw2->count + 1);
    1.21 -		array_append(&new_indexes, kw1->idx, kw1->count);
    1.22 -		for (i = 0; i < kw2->count; i++) {
    1.23 -			/* don't add duplicates */
    1.24 -			for (j = 0; j < kw1->count; j++) {
    1.25 -				if (kw1->idx[j] == kw2->idx[i])
    1.26 -					break;
    1.27 -			}
    1.28 -			if (j == kw1->count)
    1.29 -				array_append(&new_indexes, kw2->idx+i, 1);
    1.30 -		}
    1.31 -		new_kw = mailbox_keywords_create_from_indexes(box,
    1.32 -							      &new_indexes);
    1.33 -	} T_END;
    1.34 -	mailbox_keywords_unref(_kw1);
    1.35 -	mailbox_keywords_unref(_kw2);
    1.36 -	return new_kw;
    1.37 -}
    1.38 -
    1.39  static void
    1.40  mail_search_args_simplify_sub(struct mailbox *box,
    1.41  			      struct mail_search_arg *args, bool parent_and)
    1.42  {
    1.43  	struct mail_search_arg *sub, *prev = NULL;
    1.44  	struct mail_search_arg *prev_flags_arg, *prev_not_flags_arg;
    1.45 -	struct mail_search_arg *prev_kw_arg, *prev_not_kw_arg;
    1.46  
    1.47  	prev_flags_arg = prev_not_flags_arg = NULL;
    1.48 -	prev_kw_arg = prev_not_kw_arg = NULL;
    1.49  	while (args != NULL) {
    1.50  		if (args->match_not && (args->type == SEARCH_SUB ||
    1.51  					args->type == SEARCH_OR)) {
    1.52 @@ -689,35 +655,6 @@
    1.53  			}
    1.54  		}
    1.55  
    1.56 -		/* merge all keywords arguments */
    1.57 -		if (args->type == SEARCH_KEYWORDS &&
    1.58 -		    !args->match_not && parent_and) {
    1.59 -			if (prev_kw_arg == NULL)
    1.60 -				prev_kw_arg = args;
    1.61 -			else {
    1.62 -				prev_kw_arg->value.keywords =
    1.63 -					mail_search_keywords_merge(box,
    1.64 -						&prev_kw_arg->value.keywords,
    1.65 -						&args->value.keywords);
    1.66 -				prev->next = args->next;
    1.67 -				args = args->next;
    1.68 -				continue;
    1.69 -			}
    1.70 -		} else if (args->type == SEARCH_KEYWORDS &&
    1.71 -			   args->match_not && !parent_and) {
    1.72 -			if (prev_not_kw_arg == NULL)
    1.73 -				prev_not_kw_arg = args;
    1.74 -			else {
    1.75 -				prev_not_kw_arg->value.keywords =
    1.76 -					mail_search_keywords_merge(box,
    1.77 -					       &prev_not_kw_arg->value.keywords,
    1.78 -					       &args->value.keywords);
    1.79 -				prev->next = args->next;
    1.80 -				args = args->next;
    1.81 -				continue;
    1.82 -			}
    1.83 -		}
    1.84 -
    1.85  		prev = args;
    1.86  		args = args->next;
    1.87  	}