dovecot: Verify extension fields are correct when registering it...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Nov 28 15:51:00 EET 2007
details: http://hg.dovecot.org/dovecot/rev/082526b2702e
changeset: 6872:082526b2702e
user: Timo Sirainen <tss at iki.fi>
date: Wed Nov 28 15:50:55 2007 +0200
description:
Verify extension fields are correct when registering it from transaction
log.
diffstat:
3 files changed, 34 insertions(+), 34 deletions(-)
src/lib-index/mail-index-map.c | 32 ++++++++++++++------------------
src/lib-index/mail-index-private.h | 7 +++----
src/lib-index/mail-index-sync-ext.c | 29 +++++++++++++++++------------
diffs (125 lines):
diff -r f7ec019fd3f6 -r 082526b2702e src/lib-index/mail-index-map.c
--- a/src/lib-index/mail-index-map.c Wed Nov 28 15:50:22 2007 +0200
+++ b/src/lib-index/mail-index-map.c Wed Nov 28 15:50:55 2007 +0200
@@ -69,10 +69,9 @@ unsigned int mail_index_map_ext_hdr_offs
}
uint32_t
-mail_index_map_register_ext(struct mail_index_map *map, const char *name,
- uint32_t ext_offset, uint32_t hdr_size,
- uint32_t record_offset, uint32_t record_size,
- uint32_t record_align, uint32_t reset_id)
+mail_index_map_register_ext(struct mail_index_map *map,
+ const char *name, uint32_t ext_offset,
+ const struct mail_index_ext_header *ext_hdr)
{
struct mail_index_ext *ext;
uint32_t idx, empty_idx = (uint32_t)-1;
@@ -90,14 +89,16 @@ mail_index_map_register_ext(struct mail_
ext->ext_offset = ext_offset;
ext->hdr_offset = ext_offset +
mail_index_map_ext_hdr_offset(strlen(name));
- ext->hdr_size = hdr_size;
- ext->record_offset = record_offset;
- ext->record_size = record_size;
- ext->record_align = record_align;
- ext->reset_id = reset_id;
-
- ext->index_idx = mail_index_ext_register(map->index, name, hdr_size,
- record_size, record_align);
+ ext->hdr_size = ext_hdr->hdr_size;
+ ext->record_offset = ext_hdr->record_offset;
+ ext->record_size = ext_hdr->record_size;
+ ext->record_align = ext_hdr->record_align;
+ ext->reset_id = ext_hdr->reset_id;
+
+ ext->index_idx = mail_index_ext_register(map->index, name,
+ ext_hdr->hdr_size,
+ ext_hdr->record_size,
+ ext_hdr->record_align);
/* Update index ext_id -> map ext_id mapping. Fill non-used
ext_ids with (uint32_t)-1 */
@@ -238,12 +239,7 @@ static int mail_index_map_parse_extensio
return -1;
}
- mail_index_map_register_ext(map, name, ext_offset,
- ext_hdr->hdr_size,
- ext_hdr->record_offset,
- ext_hdr->record_size,
- ext_hdr->record_align,
- ext_hdr->reset_id);
+ mail_index_map_register_ext(map, name, ext_offset, ext_hdr);
t_pop();
}
return 0;
diff -r f7ec019fd3f6 -r 082526b2702e src/lib-index/mail-index-private.h
--- a/src/lib-index/mail-index-private.h Wed Nov 28 15:50:22 2007 +0200
+++ b/src/lib-index/mail-index-private.h Wed Nov 28 15:50:55 2007 +0200
@@ -283,10 +283,9 @@ bool mail_index_map_lookup_ext(struct ma
bool mail_index_map_lookup_ext(struct mail_index_map *map, const char *name,
uint32_t *idx_r);
uint32_t
-mail_index_map_register_ext(struct mail_index_map *map, const char *name,
- uint32_t ext_offset, uint32_t hdr_size,
- uint32_t record_offset, uint32_t record_size,
- uint32_t record_align, uint32_t reset_id);
+mail_index_map_register_ext(struct mail_index_map *map,
+ const char *name, uint32_t ext_offset,
+ const struct mail_index_ext_header *ext_hdr);
bool mail_index_map_get_ext_idx(struct mail_index_map *map,
uint32_t ext_id, uint32_t *idx_r);
const struct mail_index_ext *
diff -r f7ec019fd3f6 -r 082526b2702e src/lib-index/mail-index-sync-ext.c
--- a/src/lib-index/mail-index-sync-ext.c Wed Nov 28 15:50:22 2007 +0200
+++ b/src/lib-index/mail-index-sync-ext.c Wed Nov 28 15:50:55 2007 +0200
@@ -357,7 +357,7 @@ int mail_index_sync_ext_intro(struct mai
struct mail_index_map *map = ctx->view->map;
struct mail_index_ext_header ext_hdr;
const struct mail_index_ext *ext;
- const char *name;
+ const char *name, *error;
buffer_t *hdr_buf;
uint32_t ext_map_idx;
@@ -438,23 +438,28 @@ int mail_index_sync_ext_intro(struct mai
hdr_buf->used);
}
+ memset(&ext_hdr, 0, sizeof(ext_hdr));
+ ext_hdr.name_size = strlen(name);
+ ext_hdr.reset_id = u->reset_id;
+ ext_hdr.hdr_size = u->hdr_size;
+ ext_hdr.record_size = u->record_size;
+ ext_hdr.record_align = u->record_align;
+
+ if (mail_index_map_ext_hdr_check(&map->hdr, &ext_hdr,
+ name, &error) < 0) {
+ mail_index_sync_set_corrupted(ctx,
+ "Broken extension introduction: %s", error);
+ t_pop();
+ return -1;
+ }
+
/* register record offset initially using zero,
sync_ext_reorder() will fix it. */
ext_map_idx = mail_index_map_register_ext(map, name, hdr_buf->used,
- u->hdr_size, 0,
- u->record_size,
- u->record_align, u->reset_id);
-
+ &ext_hdr);
ext = array_idx(&map->extensions, ext_map_idx);
/* <ext_hdr> <name> [padding] [header data] */
- memset(&ext_hdr, 0, sizeof(ext_hdr));
- ext_hdr.name_size = strlen(name);
- ext_hdr.reset_id = ext->reset_id;
- ext_hdr.hdr_size = ext->hdr_size;
- ext_hdr.record_offset = ext->record_offset;
- ext_hdr.record_size = ext->record_size;
- ext_hdr.record_align = ext->record_align;
buffer_append(hdr_buf, &ext_hdr, sizeof(ext_hdr));
buffer_append(hdr_buf, name, strlen(name));
/* header must begin and end in correct alignment */
More information about the dovecot-cvs
mailing list