[dovecot-cvs] dovecot/src/lib-index mail-cache-fields.c, 1.23, 1.24 mail-cache.h, 1.27, 1.28

tss at dovecot.org tss at dovecot.org
Thu Nov 2 17:49:33 UTC 2006


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

Modified Files:
	mail-cache-fields.c mail-cache.h 
Log Message:
If cache file contains broken field type or decision type mark the cache
corrupted instead of assert-crashing later.



Index: mail-cache-fields.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-fields.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- mail-cache-fields.c	13 Oct 2006 15:18:40 -0000	1.23
+++ mail-cache-fields.c	2 Nov 2006 17:49:27 -0000	1.24
@@ -21,12 +21,27 @@
 	case MAIL_CACHE_FIELD_STRING:
 	case MAIL_CACHE_FIELD_HEADER:
 		return FALSE;
+
+	case MAIL_CACHE_FIELD_COUNT:
+		break;
 	}
 
 	i_unreached();
 	return FALSE;
 }
 
+static bool field_decision_is_valid(enum mail_cache_decision_type type)
+{
+	switch (type & ~MAIL_CACHE_DECISION_FORCED) {
+	case MAIL_CACHE_DECISION_NO:
+	case MAIL_CACHE_DECISION_TEMP:
+	case MAIL_CACHE_DECISION_YES:
+		return TRUE;
+	default:
+		return FALSE;
+	}
+}
+
 static int field_type_verify(struct mail_cache *cache, unsigned int idx,
 			     enum mail_cache_field_type type, unsigned int size)
 {
@@ -58,6 +73,8 @@
 	for (i = 0; i < fields_count; i++) {
 		if (hash_lookup_full(cache->field_name_hash, fields[i].name,
 				     &orig_key, &orig_value)) {
+			i_assert(fields[i].type < MAIL_CACHE_FIELD_COUNT);
+
 			fields[i].idx =
 				POINTER_CAST_TO(orig_value, unsigned int);
 			(void)field_type_verify(cache, fields[i].idx,
@@ -263,6 +280,16 @@
 			return -1;
 		}
 
+		if (types[i] > MAIL_CACHE_FIELD_COUNT) {
+			mail_cache_set_corrupted(cache, "field type corrupted");
+			return -1;
+		}
+		if (!field_decision_is_valid(decisions[i])) {
+			mail_cache_set_corrupted(cache,
+				"field decision type corrupted");
+			return -1;
+		}
+
 		if (hash_lookup_full(cache->field_name_hash, names,
 				     &orig_key, &orig_value)) {
 			/* already exists, see if decision can be updated */

Index: mail-cache.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- mail-cache.h	8 May 2006 12:48:51 -0000	1.27
+++ mail-cache.h	2 Nov 2006 17:49:29 -0000	1.28
@@ -26,7 +26,9 @@
 	MAIL_CACHE_FIELD_VARIABLE_SIZE,
 	MAIL_CACHE_FIELD_STRING,
 	MAIL_CACHE_FIELD_BITMASK,
-	MAIL_CACHE_FIELD_HEADER
+	MAIL_CACHE_FIELD_HEADER,
+
+	MAIL_CACHE_FIELD_COUNT
 };
 
 struct mail_cache_field {



More information about the dovecot-cvs mailing list