dovecot: Log an error if uid_validity field is updated unexpecte...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Feb 13 20:01:38 EET 2008
details: http://hg.dovecot.org/dovecot/rev/5e3c1fde2f78
changeset: 7234:5e3c1fde2f78
user: Timo Sirainen <tss at iki.fi>
date: Wed Feb 13 20:00:41 2008 +0200
description:
Log an error if uid_validity field is updated unexpectedly. If next_uid
field decreases log an error and ignore the update.
diffstat:
1 file changed, 24 insertions(+)
src/lib-index/mail-index-sync-update.c | 24 ++++++++++++++++++++++++
diffs (41 lines):
diff -r fd29c90047e9 -r 5e3c1fde2f78 src/lib-index/mail-index-sync-update.c
--- a/src/lib-index/mail-index-sync-update.c Wed Feb 13 18:06:02 2008 +0200
+++ b/src/lib-index/mail-index-sync-update.c Wed Feb 13 20:00:41 2008 +0200
@@ -385,6 +385,8 @@ static int sync_header_update(const stru
{
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) {
@@ -405,6 +407,28 @@ static int sync_header_update(const stru
} else if (u->offset < sizeof(map->hdr)) {
memcpy(PTR_OFFSET(&map->hdr, u->offset),
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
More information about the dovecot-cvs
mailing list