From: Phil Carmody Date: Mon, 2 Jun 2014 11:50:34 +0000 (+0300) Subject: mail-index: trivial paranoia check in expunge loop X-Git-Tag: 2.2.14.rc1~445 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e6629cb5d5e7f67d5023eda540105d32df5f2ba;p=thirdparty%2Fdovecot%2Fcore.git mail-index: trivial paranoia check in expunge loop We will later be moving the zone between the current seqs and the (end of the) previous seqs - this check ensures that the range is indeed monotonic, and thus that zone is positive in size. It can be zero right at the start, if the first seqs is (1,...) Based on draft patch by Timo Sirainen. Signed-off-by: Phil Carmody --- diff --git a/src/lib-index/mail-index-sync-update.c b/src/lib-index/mail-index-sync-update.c index 5248cb2683..f754e4d8a7 100644 --- a/src/lib-index/mail-index-sync-update.c +++ b/src/lib-index/mail-index-sync-update.c @@ -241,6 +241,7 @@ sync_expunge_range(struct mail_index_sync_map_ctx *ctx, const ARRAY_TYPE(seq_ran struct mail_index_map *map; const struct seq_range *range; unsigned int i, count; + uint32_t prev_seq2; map = mail_index_sync_get_atomic_map(ctx); @@ -255,12 +256,15 @@ sync_expunge_range(struct mail_index_sync_map_ctx *ctx, const ARRAY_TYPE(seq_ran } /* Preparatory HACK - do this in forward order so the memmove()s are pessimal! */ + prev_seq2 = 0; for (i = 0; i < count; i++) { uint32_t seq1 = range[i].seq1; uint32_t seq2 = range[i].seq2; struct mail_index_record *rec; uint32_t seq_count, seq; + i_assert(seq1 > prev_seq2); + for (seq = seq1; seq <= seq2; seq++) { rec = MAIL_INDEX_MAP_IDX(map, seq-1); mail_index_sync_header_update_counts(ctx, rec->uid, rec->flags, 0); @@ -275,6 +279,7 @@ sync_expunge_range(struct mail_index_sync_map_ctx *ctx, const ARRAY_TYPE(seq_ran map->rec_map->records_count -= seq_count; map->hdr.messages_count -= seq_count; mail_index_modseq_expunge(ctx->modseq_ctx, seq1, seq2); + prev_seq2 = seq2; } }