]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
indexer: indexer_queue_append_request() - Fix repeated insertions in queue->users...
authorMarco Bettini <marco.bettini@open-xchange.com>
Wed, 8 Jun 2022 09:56:37 +0000 (09:56 +0000)
committermarco.bettini <marco.bettini@open-xchange.com>
Wed, 8 Jun 2022 15:15:03 +0000 (15:15 +0000)
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

src/indexer/indexer-queue.c
src/indexer/test-indexer-queue.c

index c64910fcbfe86ccc84230d2c84f99e8211b1ee03..96e6e79a05d40b2c42858ec4d95ce0f1950dcc7f 100644 (file)
@@ -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,
index c1a7c2d80df92ed821fe5be80a074c7c477e07da..d2fae4df783af78990d0502c14fbfaab00d974d2 100644 (file)
@@ -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,