From: Timo Sirainen Date: Mon, 5 Apr 2010 06:16:56 +0000 (+0300) Subject: lib-index: Small code cleanup. X-Git-Tag: 2.0.beta5~202 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=eb958701f57066bce9cc8bbf9df73616bd322d09;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Small code cleanup. --HG-- branch : HEAD --- diff --git a/src/lib-index/mail-index-map.c b/src/lib-index/mail-index-map.c index 349ea8332e..0ff944e5e0 100644 --- a/src/lib-index/mail-index-map.c +++ b/src/lib-index/mail-index-map.c @@ -152,24 +152,17 @@ int mail_index_map_ext_get_next(struct mail_index_map *map, return 0; } -int mail_index_map_ext_hdr_check(const struct mail_index_header *hdr, - const struct mail_index_ext_header *ext_hdr, - const char *name, const char **error_r) +static int +mail_index_map_ext_hdr_check_record(const struct mail_index_header *hdr, + const struct mail_index_ext_header *ext_hdr, + const char **error_r) { - if ((ext_hdr->record_size == 0 && ext_hdr->hdr_size == 0) || - (ext_hdr->record_align == 0 && ext_hdr->record_size != 0)) { - *error_r = "Invalid field values"; - return -1; - } - if (*name == '\0') { - *error_r = "Broken name"; + if (ext_hdr->record_align == 0) { + *error_r = "Record field alignment is zero"; return -1; } - /* if we get here from extension introduction, record_offset=0 and - hdr->record_size hasn't been updated yet */ - if (ext_hdr->record_offset != 0 && - ext_hdr->record_offset + ext_hdr->record_size > hdr->record_size) { + if (ext_hdr->record_offset + ext_hdr->record_size > hdr->record_size) { *error_r = t_strdup_printf("Record field points " "outside record size (%u+%u > %u)", ext_hdr->record_offset, @@ -178,19 +171,40 @@ int mail_index_map_ext_hdr_check(const struct mail_index_header *hdr, return -1; } - if (ext_hdr->record_size > 0 && - (ext_hdr->record_offset % ext_hdr->record_align) != 0) { + if ((ext_hdr->record_offset % ext_hdr->record_align) != 0) { *error_r = t_strdup_printf("Record field alignment %u " "not used", ext_hdr->record_align); return -1; } - if (ext_hdr->record_offset != 0 && - (hdr->record_size % ext_hdr->record_align) != 0) { + if ((hdr->record_size % ext_hdr->record_align) != 0) { *error_r = t_strdup_printf("Record size not aligned by %u " "as required by extension", ext_hdr->record_align); return -1; } + return 0; +} + +int mail_index_map_ext_hdr_check(const struct mail_index_header *hdr, + const struct mail_index_ext_header *ext_hdr, + const char *name, const char **error_r) +{ + if (ext_hdr->record_size == 0 && ext_hdr->hdr_size == 0) { + *error_r = "Invalid field values"; + return -1; + } + if (*name == '\0') { + *error_r = "Broken name"; + return -1; + } + + /* if we get here from extension introduction, record_offset=0 and + hdr->record_size hasn't been updated yet */ + if (ext_hdr->record_offset != 0 && ext_hdr->record_size != 0) { + if (mail_index_map_ext_hdr_check_record(hdr, ext_hdr, + error_r) < 0) + return -1; + } if (ext_hdr->hdr_size > MAIL_INDEX_EXT_HEADER_MAX_SIZE) { *error_r = t_strdup_printf("Headersize too large (%u)", ext_hdr->hdr_size);