]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Don't crash if mmap_anon() doesn't succeed.
authorTimo Sirainen <tss@iki.fi>
Wed, 23 Apr 2003 13:23:14 +0000 (16:23 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 23 Apr 2003 13:23:14 +0000 (16:23 +0300)
--HG--
branch : HEAD

src/lib-index/mail-index-data.c
src/lib-index/mail-index-open.c
src/lib-index/mail-modifylog.c
src/lib-index/mail-tree.c

index 064fbf98980b6a43ab006ca920284c11cbc96c50..3b8682039c70f56dbc3c236c2e9a54211ee388db 100644 (file)
@@ -303,6 +303,11 @@ int mail_index_data_create(struct mail_index *index)
        if (fd == -1) {
                data->mmap_full_length = INDEX_DATA_INITIAL_SIZE;
                data->mmap_base = mmap_anon(data->mmap_full_length);
+               if (data->mmap_base == MAP_FAILED) {
+                       i_free(data);
+                       return index_file_set_syscall_error(index, path,
+                                                           "mmap_anon()");
+               }
 
                memcpy(data->mmap_base, &hdr, sizeof(hdr));
                data->header = data->mmap_base;
index aab06f450a390a24018f40f47ff97c8bb0056a20..b1ef18b7b80c52a6aa4a983cc2f9c6f49257b23e 100644 (file)
@@ -285,6 +285,8 @@ static int mail_index_create_memory(struct mail_index *index,
 
        index->mmap_full_length = INDEX_FILE_MIN_SIZE;
        index->mmap_base = mmap_anon(index->mmap_full_length);
+       if (index->mmap_base == MAP_FAILED)
+               return index_file_set_syscall_error(index, path, "mmap_anon()");
 
        mail_index_init_header(index, index->mmap_base);
        index->header = index->mmap_base;
index 923815b5d1a4b9a0d9c2fa9e762046aed4c04f22..812764c99779257458a43f3ff23203925b8ac18f 100644 (file)
@@ -512,12 +512,15 @@ static int modifylog_files_open_or_create(struct mail_modify_log *log)
        return FALSE;
 }
 
-static void modifylog_create_anon(struct modify_log_file *file)
+static int modifylog_create_anon(struct modify_log_file *file)
 {
        file->mmap_full_length = MODIFY_LOG_INITIAL_SIZE;
        file->mmap_base = mmap_anon(file->mmap_full_length);
        file->header = file->mmap_base;
 
+       if (file->mmap_base == MAP_FAILED)
+               return modifylog_set_syscall_error(file, "mmap_anon()");
+
        mail_modifylog_init_header(file->log, file->mmap_base);
 
        file->mmap_used_length = file->header->used_file_size;
@@ -526,6 +529,7 @@ static void modifylog_create_anon(struct modify_log_file *file)
        file->anon_mmap = TRUE;
        file->filepath = i_strdup_printf("(in-memory modify log for %s)",
                                         file->log->index->mailbox_path);
+       return TRUE;
 }
 
 int mail_modifylog_create(struct mail_index *index)
@@ -537,9 +541,12 @@ int mail_modifylog_create(struct mail_index *index)
 
        log = mail_modifylog_new(index);
 
-       if (INDEX_IS_IN_MEMORY(index))
-               modifylog_create_anon(&log->file1);
-       else {
+       if (INDEX_IS_IN_MEMORY(index)) {
+               if (!modifylog_create_anon(&log->file1)) {
+                       mail_modifylog_free(log);
+                       return FALSE;
+               }
+       } else {
                ret = modifylog_reuse_or_create_file(&log->file1);
                if (ret == 0) {
                        index_set_error(log->index,
index a9cb231ff02b7d71b37847b2f7c1fe18ee3da080..4d7f70b0968efa56613886ec8894513b14a7da7b 100644 (file)
@@ -302,6 +302,9 @@ static int mail_tree_init(struct mail_tree *tree)
        if (tree->anon_mmap) {
                tree->mmap_full_length = MAIL_TREE_MIN_SIZE;
                tree->mmap_base = mmap_anon(tree->mmap_full_length);
+               if (tree->mmap_base == MAP_FAILED)
+                       return tree_set_syscall_error(tree, "mmap_anon()");
+
                memcpy(tree->mmap_base, &hdr, sizeof(struct mail_tree_header));
                return mmap_verify(tree);
        }