Mercurial > dovecot > core-2.2
changeset 1379:42d30992c0a4 HEAD
Don't crash if mmap_anon() doesn't succeed.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 23 Apr 2003 16:23:14 +0300 |
parents | bda297ecd516 |
children | 7dff693ab2b2 |
files | 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 |
diffstat | 4 files changed, 21 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-index-data.c Tue Apr 22 21:49:00 2003 +0300 +++ b/src/lib-index/mail-index-data.c Wed Apr 23 16:23:14 2003 +0300 @@ -303,6 +303,11 @@ 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;
--- a/src/lib-index/mail-index-open.c Tue Apr 22 21:49:00 2003 +0300 +++ b/src/lib-index/mail-index-open.c Wed Apr 23 16:23:14 2003 +0300 @@ -285,6 +285,8 @@ 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;
--- a/src/lib-index/mail-modifylog.c Tue Apr 22 21:49:00 2003 +0300 +++ b/src/lib-index/mail-modifylog.c Wed Apr 23 16:23:14 2003 +0300 @@ -512,12 +512,15 @@ 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 @@ 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 @@ 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,
--- a/src/lib-index/mail-tree.c Tue Apr 22 21:49:00 2003 +0300 +++ b/src/lib-index/mail-tree.c Wed Apr 23 16:23:14 2003 +0300 @@ -302,6 +302,9 @@ 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); }