[dovecot-cvs] dovecot/src/lib-index mail-index.c, 1.230.2.18, 1.230.2.19

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


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

Modified Files:
      Tag: branch_1_0
	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.230.2.18
retrieving revision 1.230.2.19
diff -u -d -r1.230.2.18 -r1.230.2.19
--- mail-index.c	23 Jan 2007 11:19:39 -0000	1.230.2.18
+++ mail-index.c	6 Mar 2007 14:23:37 -0000	1.230.2.19
@@ -515,10 +515,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
@@ -527,18 +525,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: "
@@ -674,6 +683,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;
 
@@ -750,6 +764,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