Skip to content

Commit

Permalink
lib-storage: Fixed potential crash in mailbox_sync_deinit() error han…
Browse files Browse the repository at this point in the history
…dling

If mailbox_sync*() was called before mailbox was opened, the automatic
mailbox opening could fail. mailbox_sync_deinit() would still try to access
box->view, which would be NULL.
  • Loading branch information
sirainen committed May 11, 2016
1 parent e999ae9 commit 9700009
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/lib-storage/index/index-sync.c
Expand Up @@ -291,6 +291,17 @@ void index_sync_update_recent_count(struct mailbox *box)
}
}

static void index_mailbox_sync_free(struct index_mailbox_sync_context *ctx)
{
if (array_is_created(&ctx->flag_updates))
array_free(&ctx->flag_updates);
if (array_is_created(&ctx->hidden_updates))
array_free(&ctx->hidden_updates);
if (array_is_created(&ctx->all_flag_update_uids))
array_free(&ctx->all_flag_update_uids);
i_free(ctx);
}

int index_mailbox_sync_deinit(struct mailbox_sync_context *_ctx,
struct mailbox_sync_status *status_r)
{
Expand All @@ -314,6 +325,10 @@ int index_mailbox_sync_deinit(struct mailbox_sync_context *_ctx,
ret = -1;
}
}
if (ret < 0) {
index_mailbox_sync_free(ctx);
return -1;
}
index_mailbox_expunge_unseen_recent(ctx);

if ((_ctx->box->flags & MAILBOX_FLAG_DROP_RECENT) == 0 &&
Expand All @@ -327,18 +342,10 @@ int index_mailbox_sync_deinit(struct mailbox_sync_context *_ctx,

/* update search results after private index is updated */
index_sync_search_results_update(ctx);

if (array_is_created(&ctx->flag_updates))
array_free(&ctx->flag_updates);
if (array_is_created(&ctx->hidden_updates))
array_free(&ctx->hidden_updates);
if (array_is_created(&ctx->all_flag_update_uids))
array_free(&ctx->all_flag_update_uids);

/* update vsize header if wanted */
if (ret == 0)
index_mailbox_vsize_update_appends(_ctx->box);
i_free(ctx);
index_mailbox_vsize_update_appends(_ctx->box);

index_mailbox_sync_free(ctx);
return ret;
}

Expand Down

0 comments on commit 9700009

Please sign in to comment.