]> 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)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Mon, 26 Jun 2023 21:33:43 +0000 (21:33 +0000)
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 67290d4544b02685a0867219807294590b8f73c7..e3d648712fe04cd34ef3fcebcc533e238237dbdd 100644 (file)
@@ -174,13 +174,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;
@@ -188,11 +189,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;
@@ -210,8 +211,7 @@ dbox_cleanup_temp_files(struct mailbox_list *list, const char *path,
                struct stat st;
                if (stat(path, &st) < 0) {
                        if (errno != ENOENT)
-                               e_error(list->ns->user->event,
-                                       "stat(%s) failed: %m", path);
+                               e_error(user->event, "stat(%s) failed: %m", path);
                        return FALSE;
                }
                last_change_time = st.st_ctime;
@@ -285,7 +285,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;
@@ -298,15 +298,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;
@@ -321,7 +319,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 1476778a0b4df01315a078a28a83f7b7544b0a4a..814c3595c539e8b1b99df13652fbba993a70852e 100644 (file)
@@ -77,7 +77,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 bb3fb090302a7eaa7cda69331dc32be7df9c622e..ded89bd6860a528fd915a10d2d7a686b2e298530 100644 (file)
@@ -87,8 +87,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);
 }