From: Timo Sirainen Date: Fri, 3 Jun 2016 17:14:01 +0000 (+0300) Subject: lib-index: Fix duplicate fields in mail_cache_register_fields() X-Git-Tag: 2.2.25.rc1~187 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dab6a443b64ebb41493ea13a833c1d81cc2cbad6;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Fix duplicate fields in mail_cache_register_fields() Broken by hash_table_insert() API change. The earlier code was also a bit wrong by allocating a bit too much memory when there were duplicate fields being registered. --- diff --git a/src/lib-index/mail-cache-fields.c b/src/lib-index/mail-cache-fields.c index 98a030b9ca..a46a2e400e 100644 --- a/src/lib-index/mail-cache-fields.c +++ b/src/lib-index/mail-cache-fields.c @@ -105,7 +105,7 @@ void mail_cache_register_fields(struct mail_cache *cache, char *name; void *value; unsigned int new_idx; - unsigned int i, j; + unsigned int i, j, registered_count; new_idx = cache->fields_count; for (i = 0; i < fields_count; i++) { @@ -141,10 +141,11 @@ void mail_cache_register_fields(struct mail_cache *cache, cache->fields_count * sizeof(*cache->field_file_map), new_idx * sizeof(*cache->field_file_map)); + registered_count = cache->fields_count; for (i = 0; i < fields_count; i++) { unsigned int idx = fields[i].idx; - if (idx < cache->fields_count) + if (idx < registered_count) continue; /* new index - save it */ @@ -159,7 +160,9 @@ void mail_cache_register_fields(struct mail_cache *cache, hash_table_insert(cache->field_name_hash, name, POINTER_CAST(idx)); + registered_count++; } + i_assert(registered_count == new_idx); cache->fields_count = new_idx; }