[dovecot-cvs] dovecot/src/lib-index mail-index-private.h, 1.69.2.3, 1.69.2.4 mail-index.c, 1.230.2.11, 1.230.2.12

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


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

Modified Files:
      Tag: branch_1_0
	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.69.2.3
retrieving revision 1.69.2.4
diff -u -d -r1.69.2.3 -r1.69.2.4
--- mail-index-private.h	28 Dec 2006 16:27:41 -0000	1.69.2.3
+++ mail-index-private.h	16 Jan 2007 15:07:39 -0000	1.69.2.4
@@ -234,7 +234,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.230.2.11
retrieving revision 1.230.2.12
diff -u -d -r1.230.2.11 -r1.230.2.12
--- mail-index.c	31 Dec 2006 16:09:40 -0000	1.230.2.11
+++ mail-index.c	16 Jan 2007 15:07:39 -0000	1.230.2.12
@@ -559,11 +559,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;
 	}
 
@@ -987,10 +988,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;
@@ -1005,7 +1008,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;
 }
@@ -1029,7 +1039,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;
@@ -1151,7 +1161,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;
@@ -1219,6 +1229,8 @@
 		/* fix the name pointers to use our own pool */
 		extensions = array_get_modifyable(&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