[dovecot-cvs] dovecot/src/lib-index mail-index-transaction.c, 1.38, 1.39 mail-transaction-log.c, 1.81, 1.82

cras at dovecot.org cras at dovecot.org
Wed Jan 12 23:26:38 EET 2005


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv699/lib-index

Modified Files:
	mail-index-transaction.c mail-transaction-log.c 
Log Message:
Fixed crashes with keywords code when copying/saving many mails.



Index: mail-index-transaction.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-transaction.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- mail-index-transaction.c	10 Jan 2005 17:37:22 -0000	1.38
+++ mail-index-transaction.c	12 Jan 2005 21:26:36 -0000	1.39
@@ -60,6 +60,7 @@
 
 	if (kt->messages != NULL)
 		buffer_free(kt->messages);
+	i_free(kt);
 }
 
 static void mail_index_transaction_free(struct mail_index_transaction *t)
@@ -81,13 +82,13 @@
 	}
 
 	if (t->keyword_updates != NULL) {
-		struct mail_keyword_transaction *kt;
+		struct mail_keyword_transaction **kt;
 
 		kt = buffer_get_modifyable_data(t->keyword_updates, &size);
 		size /= sizeof(*kt);
 
 		for (i = 0; i < size; i++)
-			mail_keyword_transaction_free(&kt[i]);
+			mail_keyword_transaction_free(kt[i]);
 		buffer_free(t->keyword_updates);
 	}
 
@@ -175,16 +176,16 @@
 	}
 
 	if (t->keyword_updates != NULL) {
-		struct mail_keyword_transaction *kt;
+		struct mail_keyword_transaction **kt;
 
 		kt = buffer_get_modifyable_data(t->keyword_updates, &size);
 		size /= sizeof(*kt);
 
 		for (i = 0; i < size; i++) {
-			if (kt[i].messages == NULL)
+			if (kt[i]->messages == NULL)
 				continue;
 
-			mail_index_buffer_convert_to_uids(t, kt[i].messages,
+			mail_index_buffer_convert_to_uids(t, kt[i]->messages,
 				sizeof(uint32_t) * 2, TRUE);
 		}
 	}
@@ -746,12 +747,14 @@
 	if (t->keyword_updates == NULL)
                 t->keyword_updates = buffer_create_dynamic(default_pool, 512);
 
-	kt = buffer_append_space_unsafe(t->keyword_updates, sizeof(*kt));
+	kt = i_new(struct mail_keyword_transaction, 1);
 	kt->transaction = t;
 	kt->keywords = keywords;
 
 	kt->next = keywords->kt;
 	keywords->kt = kt;
+
+	buffer_append(t->keyword_updates, &kt, sizeof(kt));
 	return kt;
 }
 

Index: mail-transaction-log.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -d -r1.81 -r1.82
--- mail-transaction-log.c	10 Jan 2005 17:37:22 -0000	1.81
+++ mail-transaction-log.c	12 Jan 2005 21:26:36 -0000	1.82
@@ -1192,7 +1192,7 @@
 				      struct mail_index_transaction *t)
 {
 	struct mail_index *index = t->view->index;
-	struct mail_keyword_transaction *kt;
+	struct mail_keyword_transaction **kt;
 	struct mail_transaction_keyword_update kt_hdr;
 	buffer_t *buf;
 	size_t i, size, size_offset, name_offset;
@@ -1206,27 +1206,29 @@
 		buffer_set_used_size(buf, 0);
 
 		memset(&kt_hdr, 0, sizeof(kt_hdr));
-		kt_hdr.keywords_count = kt[i].keywords->count;
-		kt_hdr.modify_type = kt[i].modify_type;
+		kt_hdr.keywords_count = kt[i]->keywords->count;
+		kt_hdr.modify_type = kt[i]->modify_type;
 		buffer_append(buf, &kt_hdr,
 			      sizeof(kt_hdr) - sizeof(kt_hdr.name_size));
 
 		size_offset = buf->used;
 		name_offset = buf->used +
-			kt[i].keywords->count * sizeof(uint16_t);
+			kt[i]->keywords->count * sizeof(uint16_t);
 
 		idx = 0;
-		first_keyword = kt[i].keywords->start;
-		last_idx = kt[i].keywords->end - first_keyword;
+		first_keyword = kt[i]->keywords->start;
+		last_idx = kt[i]->keywords->end - first_keyword;
 
 		for (; idx <= last_idx; idx++) {
 			uint16_t name_size;
 			const char *keyword;
 
-			if ((kt[i].keywords->bitmask[idx / 8] &
+			if ((kt[i]->keywords->bitmask[idx / 8] &
 			     (1 << (idx % 8))) == 0)
 				continue;
 
+			i_assert(first_keyword + idx <
+				 index->keywords_buf->used / sizeof(keyword));
 			keyword = index->keywords[first_keyword + idx];
 
 			name_size = strlen(keyword);
@@ -1240,7 +1242,7 @@
 
 		if ((buf->used % 4) != 0)
 			buffer_append_zero(buf, 4 - (buf->used % 4));
-		buffer_append_buf(buf, kt[i].messages, 0, (size_t)-1);
+		buffer_append_buf(buf, kt[i]->messages, 0, (size_t)-1);
 
 		if (log_append_buffer(file, buf, NULL,
 				      MAIL_TRANSACTION_KEYWORD_UPDATE,



More information about the dovecot-cvs mailing list