From: Marco Bettini Date: Wed, 8 Jun 2022 09:56:37 +0000 (+0000) Subject: indexer: indexer_queue_append_request() - Fix repeated insertions in queue->users... X-Git-Tag: 2.4.0~3984 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f3cd2b97097a5156b9773d8323cbf9cb3e2c14d4;p=thirdparty%2Fdovecot%2Fcore.git indexer: indexer_queue_append_request() - Fix repeated insertions in queue->users indexer_queue(s) The repeated insertion happens when invoking for an existing entry and append=FALSE. At that point, the section dealing with queue->users is erroneously executed. This will cause later a panic in indexer_queue_deinit() due to the extra entries remaining in the table --- diff --git a/src/indexer/indexer-queue.c b/src/indexer/indexer-queue.c index c64910fcbf..96e6e79a05 100644 --- a/src/indexer/indexer-queue.c +++ b/src/indexer/indexer-queue.c @@ -129,6 +129,8 @@ indexer_queue_append_request(struct indexer_queue *queue, bool append, } /* move request to beginning of the queue */ DLLIST2_REMOVE(&queue->head, &queue->tail, request); + DLLIST2_PREPEND(&queue->head, &queue->tail, request); + return request; } if (!hash_table_lookup_full(queue->users, username, diff --git a/src/indexer/test-indexer-queue.c b/src/indexer/test-indexer-queue.c index c1a7c2d80d..d2fae4df78 100644 --- a/src/indexer/test-indexer-queue.c +++ b/src/indexer/test-indexer-queue.c @@ -53,6 +53,30 @@ static void test_indexer_queue(void) test_end(); } +static void test_indexer_queue_repeated_prepend(void) +{ + struct indexer_queue *queue; + struct indexer_request *request; + + test_begin("indexer queue"); + queue = indexer_queue_init(indexer_queue_status_callback); + + indexer_queue_append(queue, FALSE, "user1", "mailbox1", "session1", 0, NULL); + indexer_queue_append(queue, FALSE, "user1", "mailbox1", "session1", 0, NULL); + + test_assert_cmp(indexer_queue_count(queue), ==, 1); + + request = indexer_queue_request_peek(queue); + indexer_queue_request_remove(queue); + indexer_queue_request_finish(queue, &request, TRUE); + + test_assert(indexer_queue_request_peek(queue) == NULL); + + /* this used to assert crash before the fix */ + indexer_queue_deinit(&queue); + test_end(); +} + static void test_indexer_queue_reindex(void) { struct indexer_queue *queue; @@ -237,6 +261,7 @@ int main(void) { static void (*const test_functions[])(void) = { test_indexer_queue, + test_indexer_queue_repeated_prepend, test_indexer_queue_reindex, test_indexer_queue_cancel, test_indexer_queue_iter,