[dovecot-cvs] dovecot/src/lib-index mail-index-private.h, 1.79, 1.80 mail-index.c, 1.252, 1.253

tss at dovecot.org tss at dovecot.org
Tue Jan 16 15:07:46 UTC 2007


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv21917

Modified Files:
	mail-index-private.h mail-index.c 
Log Message:
Added some extra checks/asserts



Index: mail-index-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-private.h,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -d -r1.79 -r1.80
--- mail-index-private.h	28 Dec 2006 16:28:29 -0000	1.79
+++ mail-index-private.h	16 Jan 2007 15:07:43 -0000	1.80
@@ -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);

Index: mail-index.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.252
retrieving revision 1.253
diff -u -d -r1.252 -r1.253
--- mail-index.c	31 Dec 2006 16:09:42 -0000	1.252
+++ mail-index.c	16 Jan 2007 15:07:43 -0000	1.253
@@ -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);
 		}



More information about the dovecot-cvs mailing list