Mercurial > dovecot > core-2.2
changeset 249:f0a52521d844 HEAD
data file wasn't initialized properly
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 16 Sep 2002 08:34:44 +0300 |
parents | fbe3a420e960 |
children | 0c5832e58728 |
files | src/lib-index/mail-index-data.c |
diffstat | 1 files changed, 16 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-index-data.c Mon Sep 16 08:28:17 2002 +0300 +++ b/src/lib-index/mail-index-data.c Mon Sep 16 08:34:44 2002 +0300 @@ -126,7 +126,8 @@ i_assert(!data->anon_mmap); if (data->mmap_base != NULL) { - if (msync(data->mmap_base, data->mmap_used_length, MS_SYNC) < 0) + if (data->mmap_used_length > 0 && + msync(data->mmap_base, data->mmap_used_length, MS_SYNC) < 0) return index_data_set_syscall_error(data, "msync()"); if (munmap(data->mmap_base, data->mmap_full_length) < 0) @@ -147,6 +148,12 @@ hdr = data->mmap_base; + if (hdr->used_file_size < sizeof(MailIndexDataHeader)) { + index_data_set_corrupted(data, "used_file_size too small (" + "%"PRIuUOFF_T")", hdr->used_file_size); + return FALSE; + } + if (hdr->used_file_size > data->mmap_full_length) { index_data_set_corrupted(data, "used_file_size larger than " "real file size (%"PRIuUOFF_T @@ -206,7 +213,7 @@ { const char *realpath; - if (write_full(fd, &hdr, sizeof(hdr)) < 0) { + if (write_full(fd, hdr, sizeof(MailIndexDataHeader)) < 0) { index_file_set_syscall_error(index, temppath, "write_full()"); return NULL; } @@ -236,9 +243,9 @@ const char *temppath, *realpath; int fd; - memset(&hdr, 0, sizeof(hdr)); + memset(&hdr, 0, sizeof(MailIndexDataHeader)); hdr.indexid = index->indexid; - hdr.used_file_size = sizeof(hdr); + hdr.used_file_size = sizeof(MailIndexDataHeader); realpath = NULL; @@ -272,7 +279,7 @@ data->mmap_full_length = INDEX_DATA_INITIAL_SIZE; data->mmap_base = mmap_anon(data->mmap_full_length); - memcpy(data->mmap_base, &hdr, sizeof(hdr)); + memcpy(data->mmap_base, &hdr, sizeof(MailIndexDataHeader)); data->header = data->mmap_base; data->mmap_used_length = data->header->used_file_size; @@ -318,12 +325,12 @@ { MailIndexDataHeader hdr; - memset(&hdr, 0, sizeof(hdr)); + memset(&hdr, 0, sizeof(MailIndexDataHeader)); hdr.indexid = data->index->indexid; - hdr.used_file_size = sizeof(hdr); + hdr.used_file_size = sizeof(MailIndexDataHeader); if (data->anon_mmap) { - memcpy(data->mmap_base, &hdr, sizeof(hdr)); + memcpy(data->mmap_base, &hdr, sizeof(MailIndexDataHeader)); return TRUE; } @@ -336,7 +343,7 @@ if (lseek(data->fd, 0, SEEK_SET) < 0) return index_data_set_syscall_error(data, "lseek()"); - if (write_full(data->fd, &hdr, sizeof(hdr)) < 0) { + if (write_full(data->fd, &hdr, sizeof(MailIndexDataHeader)) < 0) { if (errno == ENOSPC) data->index->nodiskspace = TRUE; return index_data_set_syscall_error(data, "write_full()");