[dovecot-cvs] dovecot/src/lib-index mail-index-sync.c, 1.57, 1.58 mail-transaction-log-private.h, 1.11, 1.12 mail-transaction-log-view.c, 1.39, 1.40 mail-transaction-log.c, 1.95, 1.96

cras at dovecot.org cras at dovecot.org
Tue Apr 26 19:32:05 EEST 2005


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

Modified Files:
	mail-index-sync.c mail-transaction-log-private.h 
	mail-transaction-log-view.c mail-transaction-log.c 
Log Message:
Minor error checking fixes.



Index: mail-index-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- mail-index-sync.c	19 Apr 2005 13:27:47 -0000	1.57
+++ mail-index-sync.c	26 Apr 2005 16:32:02 -0000	1.58
@@ -364,7 +364,7 @@
 		   the log sequences have gotten messed up. */
 		mail_transaction_log_file_set_corrupted(index->log->head,
 			"log_file_int_offset (%u) > log size (%"PRIuUOFF_T")",
-			seq, index->hdr->log_file_int_offset, offset);
+			index->hdr->log_file_int_offset, offset);
                 mail_index_sync_rollback(ctx);
 		return -1;
 	}

Index: mail-transaction-log-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log-private.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- mail-transaction-log-private.h	23 Apr 2005 09:56:39 -0000	1.11
+++ mail-transaction-log-private.h	26 Apr 2005 16:32:02 -0000	1.12
@@ -47,7 +47,8 @@
 
 void
 mail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file,
-					const char *fmt, ...);
+					const char *fmt, ...)
+	__attr_format__(2, 3);
 
 int mail_transaction_log_file_find(struct mail_transaction_log *log,
 				   uint32_t file_seq,

Index: mail-transaction-log-view.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log-view.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- mail-transaction-log-view.c	23 Apr 2005 09:56:39 -0000	1.39
+++ mail-transaction-log-view.c	26 Apr 2005 16:32:02 -0000	1.40
@@ -322,18 +322,11 @@
 		return -1;
 	}
 
+	i_assert(view->cur_offset >= file->buffer_offset);
 	hdr = CONST_PTR_OFFSET(data, view->cur_offset - file->buffer_offset);
 	data = CONST_PTR_OFFSET(hdr, sizeof(*hdr));
 
 	hdr_size = mail_index_offset_to_uint32(hdr->size);
-	if (file_size - view->cur_offset < hdr_size) {
-		mail_transaction_log_file_set_corrupted(file,
-			"record size too large (type=0x%x, offset=%"PRIuUOFF_T
-			", size=%u, end=%"PRIuSIZE_T")",
-			hdr->type & MAIL_TRANSACTION_TYPE_MASK,
-			view->cur_offset, hdr_size, file_size);
-		return -1;
-	}
 	if (hdr_size < sizeof(*hdr)) {
 		type_rec = NULL;
 		record_size = 0;
@@ -364,6 +357,15 @@
 		return -1;
 	}
 
+	if (file_size - view->cur_offset < hdr_size) {
+		mail_transaction_log_file_set_corrupted(file,
+			"record size too large (type=0x%x, offset=%"PRIuUOFF_T
+			", size=%u, end=%"PRIuSIZE_T")",
+			hdr->type & MAIL_TRANSACTION_TYPE_MASK,
+			view->cur_offset, hdr_size, file_size);
+		return -1;
+	}
+
 	if ((hdr->type & MAIL_TRANSACTION_EXPUNGE) != 0) {
 		if ((hdr->type & MAIL_TRANSACTION_TYPE_MASK) !=
 		    (MAIL_TRANSACTION_EXPUNGE|MAIL_TRANSACTION_EXPUNGE_PROT)) {

Index: mail-transaction-log.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log.c,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -d -r1.95 -r1.96
--- mail-transaction-log.c	23 Apr 2005 09:56:39 -0000	1.95
+++ mail-transaction-log.c	26 Apr 2005 16:32:02 -0000	1.96
@@ -905,10 +905,6 @@
 		hdr_size = mail_index_offset_to_uint32(hdr->size);
 		if (hdr_size == 0) {
 			/* unfinished */
-			if (file->mmap_base == NULL) {
-				size = file->sync_offset - file->buffer_offset;
-				buffer_set_used_size(file->buffer, size);
-			}
 			return 0;
 		}
 		if (hdr_size < sizeof(*hdr)) {
@@ -917,20 +913,22 @@
 			return -1;
 		}
 
-		if (file->sync_offset - file->buffer_offset + hdr_size > size) {
-			/* record goes outside the file we've seen. or if
-			   we're accessing the log file via unlocked mmaped
-			   memory, it may be just that the memory was updated
-			   after we checked the file size. */
-			if (file->locked || file->mmap_base == NULL) {
-				mail_transaction_log_file_set_corrupted(file,
-					"hdr.size too large (%u)", hdr_size);
-				return -1;
-			}
+		if (file->sync_offset - file->buffer_offset + hdr_size > size)
 			break;
-		}
 		file->sync_offset += hdr_size;
 	}
+
+	if (file->sync_offset - file->buffer_offset != size) {
+		/* record goes outside the file we've seen. or if
+		   we're accessing the log file via unlocked mmaped
+		   memory, it may be just that the memory was updated
+		   after we checked the file size. */
+		if (file->locked || file->mmap_base == NULL) {
+			mail_transaction_log_file_set_corrupted(file,
+				"hdr.size too large (%u)", hdr_size);
+			return -1;
+		}
+	}
 	return 0;
 }
 
@@ -995,10 +993,9 @@
 
 	if (ret == 0) {
 		/* EOF */
-		if (file->sync_offset > file->buffer_offset) {
-			buffer_set_used_size(file->buffer, file->sync_offset -
-					     file->buffer_offset);
-		}
+		i_assert(file->sync_offset >= file->buffer_offset);
+		buffer_set_used_size(file->buffer,
+				     file->sync_offset - file->buffer_offset);
 		return 1;
 	}
 
@@ -1034,7 +1031,7 @@
 
 	if (start_offset < file->hdr.hdr_size) {
 		mail_transaction_log_file_set_corrupted(file,
-			"offset (%"PRIuUOFF_T") < header size (%"PRIuSIZE_T")",
+			"offset (%"PRIuUOFF_T") < header size (%u)",
 			start_offset, file->hdr.hdr_size);
 		return -1;
 	}
@@ -1126,7 +1123,7 @@
 	if (end_offset != (uoff_t)-1 && end_offset > file->sync_offset) {
 		mail_transaction_log_file_set_corrupted(file,
 			"end_offset (%"PRIuUOFF_T") > current sync_offset "
-			"(%"PRIuSIZE_T")", end_offset, file->sync_offset);
+			"(%"PRIuUOFF_T")", end_offset, file->sync_offset);
 		return -1;
 	}
 



More information about the dovecot-cvs mailing list