dovecot-2.0: lib-index: Avoid assert-crashing on keyword-update ...

dovecot at dovecot.org dovecot at dovecot.org
Wed Jan 4 17:26:35 EET 2012


details:   http://hg.dovecot.org/dovecot-2.0/rev/5ef791398c8c
changeset: 13008:5ef791398c8c
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jan 04 17:26:25 2012 +0200
description:
lib-index: Avoid assert-crashing on keyword-update record with empty keyword.

diffstat:

 src/lib-index/mail-index-sync-keywords.c  |  7 ++-----
 src/lib-index/mail-index-sync.c           |  2 ++
 src/lib-index/mail-transaction-log-view.c |  5 +++++
 3 files changed, 9 insertions(+), 5 deletions(-)

diffs (51 lines):

diff -r 69c6d7436f7f -r 5ef791398c8c src/lib-index/mail-index-sync-keywords.c
--- a/src/lib-index/mail-index-sync-keywords.c	Tue Jan 03 14:32:08 2012 +0200
+++ b/src/lib-index/mail-index-sync-keywords.c	Wed Jan 04 17:26:25 2012 +0200
@@ -261,6 +261,8 @@
 	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 @@
 	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 -r 69c6d7436f7f -r 5ef791398c8c src/lib-index/mail-index-sync.c
--- a/src/lib-index/mail-index-sync.c	Tue Jan 03 14:32:08 2012 +0200
+++ b/src/lib-index/mail-index-sync.c	Wed Jan 04 17:26:25 2012 +0200
@@ -83,6 +83,8 @@
 	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 -r 69c6d7436f7f -r 5ef791398c8c src/lib-index/mail-transaction-log-view.c
--- a/src/lib-index/mail-transaction-log-view.c	Tue Jan 03 14:32:08 2012 +0200
+++ b/src/lib-index/mail-transaction-log-view.c	Wed Jan 04 17:26:25 2012 +0200
@@ -527,6 +527,11 @@
 		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");


More information about the dovecot-cvs mailing list