[dovecot-cvs] dovecot/src/lib-index mail-index.c,1.261,1.262

tss at dovecot.org tss at dovecot.org
Tue Mar 6 16:23:43 EET 2007


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

Modified Files:
	mail-index.c 
Log Message:
Check index file's endianess earlier, otherwise we'll complain about other
problems.



Index: mail-index.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.261
retrieving revision 1.262
diff -u -d -r1.261 -r1.262
--- mail-index.c	23 Jan 2007 11:19:41 -0000	1.261
+++ mail-index.c	6 Mar 2007 14:23:40 -0000	1.262
@@ -518,10 +518,8 @@
 	return &index->keywords;
 }
 
-static int mail_index_check_header(struct mail_index *index,
-				   struct mail_index_map *map)
+static bool mail_index_check_header_compat(const struct mail_index_header *hdr)
 {
-	const struct mail_index_header *hdr = &map->hdr;
         enum mail_index_header_compat_flags compat_flags = 0;
 
 #ifndef WORDS_BIGENDIAN
@@ -530,18 +528,29 @@
 
 	if (hdr->major_version != MAIL_INDEX_MAJOR_VERSION) {
 		/* major version change - handle silently(?) */
-		return -1;
+		return FALSE;
 	}
 	if (hdr->compat_flags != compat_flags) {
 		/* architecture change - handle silently(?) */
-		return -1;
+		return FALSE;
 	}
 
-	if ((map->hdr.flags & MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0) {
+	if ((hdr->flags & MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0) {
 		/* we've already complained about it */
-		return -1;
+		return FALSE;
 	}
 
+	return TRUE;
+}
+
+static int mail_index_check_header(struct mail_index *index,
+				   struct mail_index_map *map)
+{
+	const struct mail_index_header *hdr = &map->hdr;
+
+	if (!mail_index_check_header_compat(hdr))
+		return -1;
+
 	/* following some extra checks that only take a bit of CPU */
 	if (hdr->uid_validity == 0 && hdr->next_uid != 1) {
 		mail_index_set_error(index, "Corrupted index file %s: "
@@ -677,6 +686,11 @@
 		return 0;
 	}
 
+	if (!mail_index_check_header_compat(hdr)) {
+		/* Can't use this file */
+		return 0;
+	}
+
 	map->mmap_used_size = hdr->header_size +
 		hdr->messages_count * hdr->record_size;
 
@@ -753,6 +767,11 @@
 
 	if (ret >= 0 && pos >= MAIL_INDEX_HEADER_MIN_SIZE &&
 	    (ret > 0 || pos >= hdr->base_header_size)) {
+		if (!mail_index_check_header_compat(hdr)) {
+			/* Can't use this file */
+			return 0;
+		}
+
 		if (hdr->base_header_size < MAIL_INDEX_HEADER_MIN_SIZE ||
 		    hdr->header_size < hdr->base_header_size) {
 			mail_index_set_error(index, "Corrupted index file %s: "



More information about the dovecot-cvs mailing list