dovecot: Panic if duplicate UIDs are tried to be appended within...

dovecot at dovecot.org dovecot at dovecot.org
Sat Nov 10 23:05:54 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/5a189b41f6b0
changeset: 6765:5a189b41f6b0
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Nov 10 23:05:07 2007 +0200
description:
Panic if duplicate UIDs are tried to be appended within a transaction.

diffstat:

1 file changed, 9 insertions(+), 1 deletion(-)
src/lib-index/mail-index-transaction.c |   10 +++++++++-

diffs (35 lines):

diff -r 8a342eab2f5e -r 5a189b41f6b0 src/lib-index/mail-index-transaction.c
--- a/src/lib-index/mail-index-transaction.c	Sat Nov 10 22:55:55 2007 +0200
+++ b/src/lib-index/mail-index-transaction.c	Sat Nov 10 23:05:07 2007 +0200
@@ -459,6 +459,8 @@ void mail_index_transaction_sort_appends
 
 	/* first make a copy of the UIDs and map them to sequences */
 	recs = array_get_modifiable(&t->appends, &count);
+	i_assert(count > 0);
+
 	new_uid_map = i_new(struct uid_map, count);
 	for (i = 0; i < count; i++) {
 		new_uid_map[i].idx = i;
@@ -470,8 +472,12 @@ void mail_index_transaction_sort_appends
 
 	/* sort mail records */
 	sorted_recs = i_new(struct mail_index_record, count);
-	for (i = 0; i < count; i++)
+	sorted_recs[0] = recs[new_uid_map[0].idx];
+	for (i = 1; i < count; i++) {
 		sorted_recs[i] = recs[new_uid_map[i].idx];
+		if (sorted_recs[i].uid == sorted_recs[i-1].uid)
+			i_panic("Duplicate UIDs added in transaction");
+	}
 	buffer_write(t->appends.arr.buffer, 0, sorted_recs,
 		     sizeof(*sorted_recs) * count);
 	i_free(sorted_recs);
@@ -630,6 +636,8 @@ void mail_index_append(struct mail_index
 			rec = mail_index_transaction_lookup(t, *seq_r - 1);
 			if (rec->uid > uid)
 				t->appends_nonsorted = TRUE;
+			else if (rec->uid == uid)
+				i_panic("Duplicate UIDs added in transaction");
 		}
 	}
 }


More information about the dovecot-cvs mailing list