From: Timo Sirainen Date: Wed, 4 Jan 2012 15:26:25 +0000 (+0200) Subject: lib-index: Avoid assert-crashing on keyword-update record with empty keyword. X-Git-Tag: 2.1.rc2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d200ae87140a1985fe527e6527bc4bd3035189b1;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Avoid assert-crashing on keyword-update record with empty keyword. --- diff --git a/src/lib-index/mail-index-sync-keywords.c b/src/lib-index/mail-index-sync-keywords.c index 872901afe4..5889ee0579 100644 --- a/src/lib-index/mail-index-sync-keywords.c +++ b/src/lib-index/mail-index-sync-keywords.c @@ -261,6 +261,8 @@ int mail_index_sync_keywords(struct mail_index_sync_map_ctx *ctx, unsigned int keyword_idx; int ret; + i_assert(rec->name_size > 0); + seqset_offset = sizeof(*rec) + rec->name_size; if ((seqset_offset % 4) != 0) seqset_offset += 4 - (seqset_offset % 4); @@ -270,11 +272,6 @@ int mail_index_sync_keywords(struct mail_index_sync_map_ctx *ctx, end = CONST_PTR_OFFSET(rec, hdr->size); keyword_name = t_strndup(rec + 1, rec->name_size); - if (*keyword_name == '\0') { - mail_index_sync_set_corrupted(ctx, - "Trying to use empty keyword"); - return -1; - } if (!keyword_lookup(ctx, keyword_name, &keyword_idx)) keywords_header_add(ctx, keyword_name, &keyword_idx); diff --git a/src/lib-index/mail-index-sync.c b/src/lib-index/mail-index-sync.c index 77f1747315..a806391406 100644 --- a/src/lib-index/mail-index-sync.c +++ b/src/lib-index/mail-index-sync.c @@ -83,6 +83,8 @@ static void mail_index_sync_add_keyword_update(struct mail_index_sync_ctx *ctx) uint32_t uid; size_t uidset_offset, i, size; + i_assert(u->name_size > 0); + uidset_offset = sizeof(*u) + u->name_size; if ((uidset_offset % 4) != 0) uidset_offset += 4 - (uidset_offset % 4); diff --git a/src/lib-index/mail-transaction-log-view.c b/src/lib-index/mail-transaction-log-view.c index 5c743a24f8..93bdf917fd 100644 --- a/src/lib-index/mail-transaction-log-view.c +++ b/src/lib-index/mail-transaction-log-view.c @@ -519,6 +519,11 @@ log_view_is_record_valid(struct mail_transaction_log_file *file, if ((seqset_offset % 4) != 0) seqset_offset += 4 - (seqset_offset % 4); + if (rec->name_size == 0) { + mail_transaction_log_file_set_corrupted(file, + "Trying to use empty keyword"); + return FALSE; + } if (seqset_offset > rec_size) { mail_transaction_log_file_set_corrupted(file, "Invalid keyword update record size");