dovecot: Fixed crashes at error conditions.
dovecot at dovecot.org
dovecot at dovecot.org
Sat Dec 29 07:11:16 EET 2007
details: http://hg.dovecot.org/dovecot/rev/4c6e9edfd4ce
changeset: 7054:4c6e9edfd4ce
user: Timo Sirainen <tss at iki.fi>
date: Sat Dec 29 06:13:35 2007 +0200
description:
Fixed crashes at error conditions.
diffstat:
3 files changed, 21 insertions(+), 19 deletions(-)
src/lib-index/mail-cache-sync-update.c | 8 ++++----
src/lib-index/mail-cache-transaction.c | 5 +++--
src/lib-index/mail-index-sync-update.c | 27 ++++++++++++++-------------
diffs (119 lines):
diff -r 622fa7cef9db -r 4c6e9edfd4ce src/lib-index/mail-cache-sync-update.c
--- a/src/lib-index/mail-cache-sync-update.c Sat Dec 29 05:50:06 2007 +0200
+++ b/src/lib-index/mail-cache-sync-update.c Sat Dec 29 06:13:35 2007 +0200
@@ -45,7 +45,7 @@ static int mail_cache_handler_lock(struc
int ret;
if (ctx->locked)
- return 1;
+ return MAIL_CACHE_IS_UNUSABLE(cache) ? 0 : 1;
if (ctx->lock_failed)
return 0;
@@ -59,17 +59,17 @@ static int mail_cache_handler_lock(struc
return 1;
}
-static int get_cache_file_seq(struct mail_index_view *view,
+static bool get_cache_file_seq(struct mail_index_view *view,
uint32_t *cache_file_seq_r)
{
const struct mail_index_ext *ext;
ext = mail_index_view_get_ext(view, view->index->cache->ext_id);
if (ext == NULL)
- return 0;
+ return FALSE;
*cache_file_seq_r = ext->reset_id;
- return 1;
+ return TRUE;
}
int mail_cache_expunge_handler(struct mail_index_sync_map_ctx *sync_ctx,
diff -r 622fa7cef9db -r 4c6e9edfd4ce src/lib-index/mail-cache-transaction.c
--- a/src/lib-index/mail-cache-transaction.c Sat Dec 29 05:50:06 2007 +0200
+++ b/src/lib-index/mail-cache-transaction.c Sat Dec 29 06:13:35 2007 +0200
@@ -152,11 +152,12 @@ mail_cache_transaction_open_if_needed(st
(void)mail_cache_open_and_verify(cache);
return;
}
- if (MAIL_CACHE_IS_UNUSABLE(cache))
- return;
/* see if we should try to reopen the cache file */
for (i = 0;; i++) {
+ if (MAIL_CACHE_IS_UNUSABLE(cache))
+ return;
+
if (!mail_index_map_get_ext_idx(cache->index->map,
cache->ext_id, &idx))
return;
diff -r 622fa7cef9db -r 4c6e9edfd4ce src/lib-index/mail-index-sync-update.c
--- a/src/lib-index/mail-index-sync-update.c Sat Dec 29 05:50:06 2007 +0200
+++ b/src/lib-index/mail-index-sync-update.c Sat Dec 29 06:13:35 2007 +0200
@@ -192,7 +192,7 @@ mail_index_header_update_lowwaters(struc
}
}
-static int
+static void
sync_expunge_call_handlers(struct mail_index_sync_map_ctx *ctx,
uint32_t seq1, uint32_t seq2)
{
@@ -202,25 +202,27 @@ sync_expunge_call_handlers(struct mail_i
/* call expunge handlers only when syncing index file */
if (ctx->type != MAIL_INDEX_SYNC_HANDLER_FILE)
- return 0;
+ return;
if (!ctx->expunge_handlers_set)
mail_index_sync_init_expunge_handlers(ctx);
if (!array_is_created(&ctx->expunge_handlers))
- return 0;
+ return;
eh = array_get(&ctx->expunge_handlers, &count);
for (i = 0; i < count; i++, eh++) {
for (; seq1 <= seq2; seq1++) {
rec = MAIL_INDEX_MAP_IDX(ctx->view->map, seq1-1);
- if (eh->handler(ctx, seq1,
- PTR_OFFSET(rec, eh->record_offset),
- eh->sync_context, eh->context) < 0)
- return -1;
- }
- }
- return 0;
+ /* FIXME: does expunge handler's return value matter?
+ we probably shouldn't disallow expunges if the
+ handler returns failure.. should it be just changed
+ to return void? */
+ (void)eh->handler(ctx, seq1,
+ PTR_OFFSET(rec, eh->record_offset),
+ eh->sync_context, eh->context);
+ }
+ }
}
static int
@@ -238,6 +240,8 @@ sync_expunge(const struct mail_transacti
/* everything expunged already */
continue;
}
+
+ sync_expunge_call_handlers(ctx, seq1, seq2);
map = mail_index_sync_get_atomic_map(ctx);
for (seq = seq1; seq <= seq2; seq++) {
@@ -246,9 +250,6 @@ sync_expunge(const struct mail_transacti
rec->flags, 0,
FALSE);
}
-
- if (sync_expunge_call_handlers(ctx, seq1, seq2) < 0)
- return -1;
/* @UNSAFE */
memmove(MAIL_INDEX_MAP_IDX(map, seq1-1),
More information about the dovecot-cvs
mailing list