[dovecot-cvs] dovecot/src/lib-index mail-index-sync-ext.c,1.4,1.5

cras at dovecot.org cras at dovecot.org
Wed Jan 26 20:58:52 EET 2005


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

Modified Files:
	mail-index-sync-ext.c 
Log Message:
Don't crash when extension header is resized and there are extensions after
it.



Index: mail-index-sync-ext.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync-ext.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- mail-index-sync-ext.c	16 Jan 2005 18:41:58 -0000	1.4
+++ mail-index-sync-ext.c	26 Jan 2005 18:58:49 -0000	1.5
@@ -318,6 +318,18 @@
 		ext_hdr->record_align = ext->record_align;
 	}
 
+	if (new_size != old_size) {
+		/* move all hdr_offset of all extensions after this one */
+		size_t i, count = map->extensions->used / sizeof(*ext);
+
+		ext -= ext_id;
+		for (i = ext_id + 1; i < count; i++) {
+			i_assert(ext[i].hdr_offset > ext[i-1].hdr_offset);
+			ext[i].hdr_offset +=
+				(ssize_t)new_size - (ssize_t)old_size;
+		}
+	}
+
 	if (old_record_size != u->record_size) {
 		map = sync_ext_reorder(map, ext_id, old_record_size);
 		mail_index_sync_replace_map(ctx, map);



More information about the dovecot-cvs mailing list