]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mail_index_get_keywords() / status.keywords weren't actually guaranteed to be NULL...
authorTimo Sirainen <tss@iki.fi>
Thu, 4 Aug 2011 16:57:02 +0000 (19:57 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 4 Aug 2011 16:57:02 +0000 (19:57 +0300)
This could have caused crashes or garbage keywords be presented to clients
in some situations.

src/lib-index/mail-index.c

index bd0559e04659a3a2c7c65d0821b7cacbe148f9d9..25200654b87c83baaf1cc9997bdbf40939a2db8b 100644 (file)
@@ -265,6 +265,10 @@ void mail_index_keyword_lookup_or_create(struct mail_index *index,
        hash_table_insert(index->keywords_hash,
                          keyword_dup, POINTER_CAST(*idx_r));
        array_append(&index->keywords, &keyword, 1);
+
+       /* keep the array NULL-terminated, but the NULL itself invisible */
+       (void)array_append_space(&index->keywords);
+       array_delete(&index->keywords, array_count(&index->keywords)-1, 1);
 }
 
 const ARRAY_TYPE(keywords) *mail_index_get_keywords(struct mail_index *index)