changeset 5212:0866a2b60b2b HEAD

Check index file's endianess earlier, otherwise we'll complain about other problems.
author Timo Sirainen <tss@iki.fi>
date Tue, 06 Mar 2007 16:23:40 +0200
parents 6d4c18b51495
children 2969edccb9b0
files src/lib-index/mail-index.c
diffstat 1 files changed, 27 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index.c	Tue Mar 06 15:45:23 2007 +0200
+++ b/src/lib-index/mail-index.c	Tue Mar 06 16:23:40 2007 +0200
@@ -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,17 +528,28 @@
 
 	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 ((hdr->flags & MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0) {
+		/* we've already complained about it */
+		return FALSE;
 	}
 
-	if ((map->hdr.flags & MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0) {
-		/* we've already complained about it */
+	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) {
@@ -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: "