]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dbox: Fix for dangling pointer being passed to cleanup_interval()
authorMarco Bettini <marco.bettini@open-xchange.com>
Mon, 26 Jun 2023 10:43:00 +0000 (10:43 +0000)
committerMarkus Valentin <markus.valentin@open-xchange.com>
Wed, 28 Jun 2023 12:26:57 +0000 (14:26 +0200)
Broken in 88eee28fd86d619b26ce6aebadca5b18e748dc6f

src/lib-storage/index/dbox-common/dbox-storage.c
src/lib-storage/index/dbox-common/dbox-storage.h
src/lib-storage/index/dbox-multi/mdbox-map.c

index b006412f59b4a1ed2589240a9b3fecbb19a80950..3087174b4725520cf40c91a19fb4526c35054ead 100644 (file)
@@ -172,13 +172,14 @@ void dbox_notify_changes(struct mailbox *box)
        }
 }
 
-static time_t cleanup_interval(struct mailbox_list *list)
+static time_t cleanup_interval(struct mail_user *user)
 {
-       time_t interval = list->mail_set->mail_temp_scan_interval;
+       const struct mail_storage_settings *set =
+               mail_user_set_get_storage_set(user);
+       time_t interval = set->mail_temp_scan_interval;
 
-       const char *username = list->ns->user->username;
        /* No need for a cryptographic-quality hash here. */
-       unsigned int hash = crc32_str(username);
+       unsigned int hash = crc32_str(user->username);
 
        /* spread from 0.00 to to 30.00% more than the base interval */
        unsigned int spread_factor = 100000 + hash % 30001;
@@ -186,11 +187,11 @@ static time_t cleanup_interval(struct mailbox_list *list)
 }
 
 static bool
-dbox_cleanup_temp_files(struct mailbox_list *list, const char *path,
+dbox_cleanup_temp_files(struct mail_user *user, const char *path,
                        time_t last_scan_time, time_t last_change_time)
 {
        /* check once in a while if there are temp files to clean up */
-       time_t interval = cleanup_interval(list);
+       time_t interval = cleanup_interval(user);
        if (interval == 0) {
                /* disabled */
                return FALSE;
@@ -282,7 +283,7 @@ int dbox_mailbox_open(struct mailbox *box)
        return 0;
 }
 
-int dbox_mailbox_list_cleanup(struct mailbox_list *list, const char *path,
+int dbox_mailbox_list_cleanup(struct mail_user *user, const char *path,
                              time_t last_temp_file_scan)
 {
        time_t change_time = -1;
@@ -295,15 +296,13 @@ int dbox_mailbox_list_cleanup(struct mailbox_list *list, const char *path,
                        last_temp_file_scan = stats.st_atim.tv_sec;
                        change_time = stats.st_ctim.tv_sec;
                } else {
-                       if (errno != ENOENT) {
-                               e_error(list->ns->user->event,
-                                       "stat(%s) failed: %m", path);
-                       }
+                       if (errno != ENOENT)
+                               e_error(user->event, "stat(%s) failed: %m", path);
                        return -1;
                }
        }
 
-       if (dbox_cleanup_temp_files(list, path, last_temp_file_scan, change_time) ||
+       if (dbox_cleanup_temp_files(user, path, last_temp_file_scan, change_time) ||
            last_temp_file_scan == 0) {
                /* temp files were scanned. update the last scan timestamp. */
                return 1;
@@ -318,7 +317,8 @@ void dbox_mailbox_close_cleanup(struct mailbox *box)
 
        const struct mail_index_header *hdr =
                mail_index_get_header(box->view);
-       if (dbox_mailbox_list_cleanup(box->list, mailbox_get_path(box),
+       if (dbox_mailbox_list_cleanup(box->storage->user,
+                                     mailbox_get_path(box),
                                      hdr->last_temp_file_scan) > 0)
                index_mailbox_update_last_temp_file_scan(box);
 }
index 9a85fee4d99942ccec36ae709d79df227045ff61..8e8aaa189976601844affaf345c9596c2d9e2eb8 100644 (file)
@@ -76,7 +76,7 @@ int dbox_mailbox_check_existence(struct mailbox *box);
 int dbox_mailbox_open(struct mailbox *box);
 void dbox_mailbox_close(struct mailbox *box);
 void dbox_mailbox_close_cleanup(struct mailbox *box);
-int dbox_mailbox_list_cleanup(struct mailbox_list *list, const char *path,
+int dbox_mailbox_list_cleanup(struct mail_user *user, const char *path,
                              time_t last_temp_file_scan);
 int dbox_mailbox_create(struct mailbox *box,
                        const struct mailbox_update *update, bool directory);
index eaace6fc1f5359d69c01eabf8f352187a4af1e99..f9bac0b9705bb3ca1e5531fa99c231ac4a0bc6c3 100644 (file)
@@ -84,8 +84,8 @@ static void mdbox_map_deinit_cleanup(struct mdbox_map *map)
 
        const struct mail_index_header *hdr =
                mail_index_get_header(map->view);
-       if (dbox_mailbox_list_cleanup(map->root_list, map->path,
-                                     hdr->last_temp_file_scan) > 0)
+       if (dbox_mailbox_list_cleanup(map->storage->storage.storage.user,
+                                     map->path, hdr->last_temp_file_scan) > 0)
                index_mailbox_view_update_last_temp_file_scan(map->view);
 }