[dovecot-cvs] dovecot/src/lib-index mail-cache-fields.c, 1.21.2.2, 1.21.2.3 mail-cache.h, 1.26, 1.26.2.1

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


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

Modified Files:
      Tag: branch_1_0
	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.21.2.2
retrieving revision 1.21.2.3
diff -u -d -r1.21.2.2 -r1.21.2.3
--- mail-cache-fields.c	13 Oct 2006 15:18:38 -0000	1.21.2.2
+++ mail-cache-fields.c	2 Nov 2006 17:49:26 -0000	1.21.2.3
@@ -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.26
retrieving revision 1.26.2.1
diff -u -d -r1.26 -r1.26.2.1
--- mail-cache.h	14 Jan 2006 18:47:34 -0000	1.26
+++ mail-cache.h	2 Nov 2006 17:49:26 -0000	1.26.2.1
@@ -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