dovecot: Make sure extensions updates don't modify keywords.

dovecot at dovecot.org dovecot at dovecot.org
Sat Sep 15 08:56:02 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/06818dd6a952
changeset: 6373:06818dd6a952
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Sep 15 08:55:57 2007 +0300
description:
Make sure extensions updates don't modify keywords.

diffstat:

3 files changed, 20 insertions(+), 4 deletions(-)
src/lib-index/mail-index-sync-ext.c      |   19 ++++++++++++++++---
src/lib-index/mail-index-sync-keywords.c |    4 +++-
src/lib-index/mail-index-sync-private.h  |    1 +

diffs (72 lines):

diff -r f33ea6ff46ea -r 06818dd6a952 src/lib-index/mail-index-sync-ext.c
--- a/src/lib-index/mail-index-sync-ext.c	Sat Sep 15 08:54:43 2007 +0300
+++ b/src/lib-index/mail-index-sync-ext.c	Sat Sep 15 08:55:57 2007 +0300
@@ -391,11 +391,23 @@ int mail_index_sync_ext_intro(struct mai
 		if (!mail_index_map_lookup_ext(map, name, &ext_map_idx))
 			ext_map_idx = (uint32_t)-1;
 	}
+	ext = ext_map_idx == (uint32_t)-1 ? NULL :
+		array_idx(&map->extensions, ext_map_idx);
+	if (ext != NULL)
+		name = ext->name;
+
+	if (!ctx->internal_update && strcmp(name, "keywords") == 0) {
+		/* Keyword extension is handled internally by the keyword
+		   code. Any attempt to modify them directly could cause
+		   assert-crashes later, so prevent them immediately. */
+		mail_index_sync_set_corrupted(ctx,
+			"Extension introduction for keywords");
+		t_pop();
+		return -1;
+	}
 
 	if (ext_map_idx != (uint32_t)-1) {
 		/* exists already */
-		ext = array_idx(&map->extensions, ext_map_idx);
-
 		if (u->reset_id == ext->reset_id) {
 			/* check if we need to resize anything */
 			sync_ext_resize(u, ext_map_idx, ctx);
@@ -462,7 +474,8 @@ int mail_index_sync_ext_intro(struct mai
 	sync_ext_reorder(map, ext_map_idx, 0);
 
 	ctx->cur_ext_ignore = FALSE;
-	ctx->cur_ext_map_idx = ext_map_idx;
+	ctx->cur_ext_map_idx = ctx->internal_update ?
+		(uint32_t)-1 : ext_map_idx;
 	return 1;
 }
 
diff -r f33ea6ff46ea -r 06818dd6a952 src/lib-index/mail-index-sync-keywords.c
--- a/src/lib-index/mail-index-sync-keywords.c	Sat Sep 15 08:54:43 2007 +0300
+++ b/src/lib-index/mail-index-sync-keywords.c	Sat Sep 15 08:55:57 2007 +0300
@@ -101,15 +101,17 @@ static void keywords_ext_register(struct
 		buffer_append(ext_intro_buf, "keywords", u->name_size);
 	}
 
+	ctx->internal_update = TRUE;
 	if (mail_index_sync_ext_intro(ctx, u) < 0)
 		i_panic("Keyword extension growing failed");
+	ctx->internal_update = FALSE;
 }
 
 static void
 keywords_header_add(struct mail_index_sync_map_ctx *ctx,
 		    const char *keyword_name, unsigned int *keyword_idx_r)
 {
-	struct mail_index_map *map = ctx->view->map;
+	struct mail_index_map *map;
         const struct mail_index_ext *ext = NULL;
 	struct mail_index_keyword_header *kw_hdr;
 	struct mail_index_keyword_header_rec kw_rec;
diff -r f33ea6ff46ea -r 06818dd6a952 src/lib-index/mail-index-sync-private.h
--- a/src/lib-index/mail-index-sync-private.h	Sat Sep 15 08:54:43 2007 +0300
+++ b/src/lib-index/mail-index-sync-private.h	Sat Sep 15 08:55:57 2007 +0300
@@ -39,6 +39,7 @@ struct mail_index_sync_map_ctx {
 	unsigned int expunge_handlers_set:1;
 	unsigned int expunge_handlers_used:1;
 	unsigned int cur_ext_ignore:1;
+	unsigned int internal_update:1; /* used by keywords for ext_intro */
 	unsigned int errors:1;
 };
 


More information about the dovecot-cvs mailing list