changeset 7235:40b6d4113e52 HEAD

Log an error if uid_validity field is updated unexpectedly. If next_uid field decreases log an error and ignore the update.
author Timo Sirainen <tss@iki.fi>
date Wed, 13 Feb 2008 20:00:41 +0200
parents b8b100c7771c
children b0b2c620a2b5
files src/lib-index/mail-index-sync-update.c
diffstat 1 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index-sync-update.c	Wed Feb 13 18:06:03 2008 +0200
+++ b/src/lib-index/mail-index-sync-update.c	Wed Feb 13 20:00:41 2008 +0200
@@ -385,6 +385,8 @@
 {
 	struct mail_index_map *map = ctx->view->map;
 	uint32_t orig_log_file_tail_offset = map->hdr.log_file_tail_offset;
+	uint32_t orig_next_uid = map->hdr.next_uid;
+	uint32_t orig_uid_validity = map->hdr.uid_validity;
 
 	if (u->offset >= map->hdr.base_header_size ||
 	    u->offset + u->size > map->hdr.base_header_size) {
@@ -407,6 +409,28 @@
 		       u + 1, sizeof(map->hdr) - u->offset);
 	}
 
+	/* UIDVALIDITY can be changed only by resetting the index */
+#define MAIL_INDEX_HEADER_UPDATE_FIELD_IN_RANGE(u, field) \
+	((u)->offset <= offsetof(struct mail_index_header, field) && \
+	 (u)->offset + (u)->size > offsetof(struct mail_index_header, field))
+
+
+	if (orig_uid_validity != 0 &&
+	    MAIL_INDEX_HEADER_UPDATE_FIELD_IN_RANGE(u, uid_validity)) {
+		mail_index_sync_set_corrupted(ctx,
+			"uid_validity updated unexpectedly: %u -> %u",
+			orig_uid_validity, map->hdr.uid_validity);
+		/* let it through anyway, although this could give wrong
+		   "next_uid shrank" errors if the value actually changed.. */
+	}
+	if (map->hdr.next_uid < orig_next_uid) {
+		mail_index_sync_set_corrupted(ctx,
+			"next_uid shrank ignored: %u -> %u",
+			orig_next_uid, map->hdr.next_uid);
+		map->hdr.next_uid = orig_next_uid;
+		return -1;
+	}
+
 	/* the tail offset updates are intended for internal transaction
 	   log handling. we'll update the offset in the header only when
 	   the sync is finished. */