From: Timo Sirainen Date: Fri, 5 Sep 2008 16:21:47 +0000 (+0300) Subject: strmap: Make sure the records array is always zero-terminated. X-Git-Tag: 1.2.alpha1~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b6dff2ba7a4640c1c4fa8fcad5602d236c31a2e4;p=thirdparty%2Fdovecot%2Fcore.git strmap: Make sure the records array is always zero-terminated. --HG-- branch : HEAD --- diff --git a/src/lib-index/mail-index-strmap.c b/src/lib-index/mail-index-strmap.c index bf7f4ea64e..6f74c86e74 100644 --- a/src/lib-index/mail-index-strmap.c +++ b/src/lib-index/mail-index-strmap.c @@ -789,6 +789,14 @@ void mail_index_strmap_view_sync_add_unique(struct mail_index_strmap_view_sync * view->last_ref_index = ref_index; } +static void +mail_index_strmap_zero_terminate(struct mail_index_strmap_view *view) +{ + /* zero-terminate the records array */ + (void)array_append_space(&view->recs); + array_delete(&view->recs, array_count(&view->recs)-1, 1); +} + static void mail_index_strmap_view_renumber(struct mail_index_strmap_view *view) { struct mail_index_strmap_read_context ctx; @@ -835,6 +843,7 @@ static void mail_index_strmap_view_renumber(struct mail_index_strmap_view *view) i_assert(renumber_map[0] == 0); array_delete(&view->recs, dest, i-dest); array_delete(&view->recs_crc32, dest, i-dest); + mail_index_strmap_zero_terminate(view); /* notify caller of the renumbering */ i_assert(str_idx <= view->next_str_idx); @@ -1207,6 +1216,7 @@ void mail_index_strmap_view_sync_commit(struct mail_index_strmap_view_sync **_sy i_free(sync); (void)mail_index_strmap_write(view); + mail_index_strmap_zero_terminate(view); /* zero-terminate the records array */ (void)array_append_space(&view->recs); @@ -1220,5 +1230,6 @@ void mail_index_strmap_view_sync_rollback(struct mail_index_strmap_view_sync **_ *_sync = NULL; mail_index_strmap_view_reset(sync->view); + mail_index_strmap_zero_terminate(sync->view); i_free(sync); } diff --git a/src/lib-storage/index/index-thread.c b/src/lib-storage/index/index-thread.c index 8f8e5cb508..463577e7a6 100644 --- a/src/lib-storage/index/index-thread.c +++ b/src/lib-storage/index/index-thread.c @@ -546,6 +546,9 @@ static int mail_thread_cache_sync_add(struct mail_thread_mailbox *tbox, MAILBOX_SEARCH_RESULT_FLAG_QUEUE_SYNC); msgid_map = array_get(tbox->msgid_map, &count); + /* we're relying on the array being zero-terminated (outside used + count - kind of kludgy) */ + i_assert(msgid_map[count].uid == 0); i = 0; while (i < count && mailbox_search_next(search_ctx, mail) > 0) { while (msgid_map[i].uid < mail->uid)