Mercurial > dovecot > original-hg > dovecot-1.2
changeset 5008:5ea657b6d83c HEAD
Added some extra checks/asserts
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 16 Jan 2007 17:07:43 +0200 |
parents | 37e0b70b8926 |
children | 06b281c1f543 |
files | src/lib-index/mail-index-private.h src/lib-index/mail-index.c |
diffstat | 2 files changed, 20 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-index-private.h Tue Jan 16 16:09:23 2007 +0200 +++ b/src/lib-index/mail-index-private.h Tue Jan 16 17:07:43 2007 +0200 @@ -245,7 +245,8 @@ /* Unreference given mapping and unmap it if it's dropped to zero. */ void mail_index_unmap(struct mail_index *index, struct mail_index_map **map); struct mail_index_map * -mail_index_map_clone(struct mail_index_map *map, uint32_t new_record_size); +mail_index_map_clone(const struct mail_index_map *map, + uint32_t new_record_size); uint32_t mail_index_map_lookup_ext(struct mail_index_map *map, const char *name);
--- a/src/lib-index/mail-index.c Tue Jan 16 16:09:23 2007 +0200 +++ b/src/lib-index/mail-index.c Tue Jan 16 17:07:43 2007 +0200 @@ -561,11 +561,12 @@ return 0; if (map->records_count > 0) { - /* last message's UID must be smaller than next_uid */ + /* last message's UID must be smaller than next_uid. + also make sure it's not zero. */ const struct mail_index_record *rec; rec = MAIL_INDEX_MAP_IDX(map, map->records_count-1); - if (rec->uid >= hdr->next_uid) + if (rec->uid == 0 || rec->uid >= hdr->next_uid) return 0; } @@ -989,10 +990,12 @@ } } -static int mail_index_map_try_existing(struct mail_index_map *map) +static int mail_index_map_try_existing(struct mail_index *index) { + struct mail_index_map *map = index->map; const struct mail_index_header *hdr; size_t used_size; + int ret; if (MAIL_INDEX_MAP_IS_IN_MEMORY(map)) return 0; @@ -1007,7 +1010,14 @@ if (map->mmap_size >= used_size && map->hdr_base == hdr) { map->records_count = hdr->messages_count; mail_index_map_copy_hdr(map, hdr); - return 1; + + /* make sure the header is still valid. it also re-parses + extensions although they shouldn't change without the whole + index being recreated */ + ret = mail_index_check_header(index, map); + if (ret > 0) + return 1; + /* broken. fallback to re-mmaping which will catch it */ } return 0; } @@ -1031,7 +1041,7 @@ if (!force && index->map != NULL) { i_assert(index->hdr != NULL); - ret = mail_index_map_try_existing(index->map); + ret = mail_index_map_try_existing(index); if (ret != 0) { index->mapping = FALSE; return ret; @@ -1153,7 +1163,7 @@ } struct mail_index_map * -mail_index_map_clone(struct mail_index_map *map, uint32_t new_record_size) +mail_index_map_clone(const struct mail_index_map *map, uint32_t new_record_size) { struct mail_index_map *mem_map; struct mail_index_header *hdr; @@ -1221,6 +1231,8 @@ /* fix the name pointers to use our own pool */ extensions = array_get_modifiable(&mem_map->extensions, &count); for (i = 0; i < count; i++) { + i_assert(extensions[i].record_offset + + extensions[i].record_size <= hdr->record_size); extensions[i].name = p_strdup(mem_map->extension_pool, extensions[i].name); }