[dovecot-cvs] dovecot/src/lib-index mail-cache-lookup.c, 1.26,
1.27 mail-cache-private.h, 1.18, 1.19 mail-cache-transaction.c,
1.34, 1.35
cras at dovecot.org
cras at dovecot.org
Mon Nov 29 14:30:29 EET 2004
Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv10698/lib-index
Modified Files:
mail-cache-lookup.c mail-cache-private.h
mail-cache-transaction.c
Log Message:
Crashfixes for reading corrupted cache files.
Index: mail-cache-lookup.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-lookup.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- mail-cache-lookup.c 8 Nov 2004 00:40:41 -0000 1.26
+++ mail-cache-lookup.c 29 Nov 2004 12:30:27 -0000 1.27
@@ -9,40 +9,43 @@
#define CACHE_PREFETCH 1024
-const struct mail_cache_record *
-mail_cache_get_record(struct mail_cache *cache, uint32_t offset)
+int mail_cache_get_record(struct mail_cache *cache, uint32_t offset,
+ const struct mail_cache_record **rec_r)
{
const struct mail_cache_record *cache_rec;
+ *rec_r = NULL;
if (offset == 0)
- return NULL;
+ return 0;
if (mail_cache_map(cache, offset,
sizeof(*cache_rec) + CACHE_PREFETCH) < 0)
- return NULL;
+ return -1;
if (offset + sizeof(*cache_rec) > cache->mmap_length) {
mail_cache_set_corrupted(cache, "record points outside file");
- return NULL;
+ return -1;
}
cache_rec = CACHE_RECORD(cache, offset);
if (cache_rec->size < sizeof(*cache_rec)) {
mail_cache_set_corrupted(cache, "invalid record size");
- return NULL;
+ return -1;
}
if (cache_rec->size > CACHE_PREFETCH) {
if (mail_cache_map(cache, offset, cache_rec->size) < 0)
- return NULL;
+ return -1;
cache_rec = CACHE_RECORD(cache, offset);
}
if (cache_rec->size > cache->mmap_length ||
offset + cache_rec->size > cache->mmap_length) {
mail_cache_set_corrupted(cache, "record points outside file");
- return NULL;
+ return -1;
}
- return cache_rec;
+
+ *rec_r = cache_rec;
+ return 0;
}
static int
@@ -94,7 +97,8 @@
unsigned int field;
int ret;
- cache_rec = mail_cache_get_record(view->cache, *offset);
+ if (mail_cache_get_record(view->cache, *offset, &cache_rec) < 0)
+ return -1;
if (cache_rec == NULL) {
*offset = 0;
return 1;
@@ -126,7 +130,9 @@
/* field reading might have re-mmaped the file and
caused cache_rec to break. need to get it again. */
- cache_rec = mail_cache_get_record(view->cache, *offset);
+ if (mail_cache_get_record(view->cache, *offset,
+ &cache_rec) < 0)
+ return -1;
i_assert(cache_rec != NULL);
}
Index: mail-cache-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-private.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- mail-cache-private.h 8 Nov 2004 00:40:41 -0000 1.18
+++ mail-cache-private.h 29 Nov 2004 12:30:27 -0000 1.19
@@ -178,8 +178,8 @@
int mail_cache_header_fields_get_next_offset(struct mail_cache *cache,
uint32_t *offset_r);
-const struct mail_cache_record *
-mail_cache_get_record(struct mail_cache *cache, uint32_t offset);
+int mail_cache_get_record(struct mail_cache *cache, uint32_t offset,
+ const struct mail_cache_record **rec_r);
int mail_cache_foreach(struct mail_cache_view *view, uint32_t seq,
mail_cache_foreach_callback_t *callback, void *context);
Index: mail-cache-transaction.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-transaction.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- mail-cache-transaction.c 29 Nov 2004 01:25:45 -0000 1.34
+++ mail-cache-transaction.c 29 Nov 2004 12:30:27 -0000 1.35
@@ -768,7 +768,8 @@
i_assert(cache->locked);
- cache_rec = mail_cache_get_record(cache, offset);
+ if (mail_cache_get_record(cache, offset, &cache_rec) < 0)
+ return -1;
if (cache_rec == NULL)
return 0;
@@ -779,8 +780,9 @@
expunged. */
do {
cache->hdr_copy.deleted_space += cache_rec->size;
- cache_rec =
- mail_cache_get_record(cache, cache_rec->prev_offset);
+ if (mail_cache_get_record(cache, cache_rec->prev_offset,
+ &cache_rec) < 0)
+ return -1;
} while (cache_rec != NULL);
cache->hdr_modified = TRUE;
More information about the dovecot-cvs
mailing list