changeset 139:71246aeb262d HEAD

verify that mail_hash_lookup_uid() returns offset to correct record.
author Timo Sirainen <tss@iki.fi>
date Wed, 04 Sep 2002 00:12:21 +0300
parents 945063e0fb85
children f62c2eee1fa8
files src/lib-index/mail-index.c src/lib-index/mail-messageset.c
diffstat 2 files changed, 21 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index.c	Wed Sep 04 00:02:32 2002 +0300
+++ b/src/lib-index/mail-index.c	Wed Sep 04 00:12:21 2002 +0300
@@ -1000,8 +1000,19 @@
 	for (uid = first_uid; uid <= last_try_uid; uid++) {
 		pos = mail_hash_lookup_uid(index->hash, uid);
 		if (pos != 0) {
-			return (MailIndexRecord *)
+			rec = (MailIndexRecord *)
 				((char *) index->mmap_base + pos);
+			if (rec->uid != uid) {
+				index_set_error(index,
+						"Corrupted hash for index %s: "
+						"lookup returned offset to "
+						"different UID",
+						index->filepath);
+				index->set_flags |=
+					MAIL_INDEX_FLAG_REBUILD_HASH;
+				rec = NULL;
+			}
+			return rec;
 		}
 	}
 
--- a/src/lib-index/mail-messageset.c	Wed Sep 04 00:02:32 2002 +0300
+++ b/src/lib-index/mail-messageset.c	Wed Sep 04 00:12:21 2002 +0300
@@ -218,6 +218,15 @@
 		}
 
 		rec = (MailIndexRecord *) ((char *) index->mmap_base + pos);
+		if (rec->uid != uid) {
+			/* hash is corrupted */
+			index_set_error(index, "Corrupted hash for index %s: "
+					"lookup returned offset to "
+					"different UID", index->filepath);
+
+			index->set_flags |= MAIL_INDEX_FLAG_REBUILD_HASH;
+			return -1;
+		}
 	} else {
 		/* ..however if for any reason it doesn't,
 		   still handle it properly */