dovecot-2.2: lib-storage: Make sure mailbox names are valid UTF-...
dovecot at dovecot.org
dovecot at dovecot.org
Thu Oct 23 00:11:05 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/b534125f8baf
changeset: 17981:b534125f8baf
user: Timo Sirainen <tss at iki.fi>
date: Thu Oct 23 03:10:12 2014 +0300
description:
lib-storage: Make sure mailbox names are valid UTF-8 with LAYOUT=index
diffstat:
src/lib-storage/list/mailbox-list-index.c | 22 ++++++++++++++++------
1 files changed, 16 insertions(+), 6 deletions(-)
diffs (55 lines):
diff -r c373aa97644c -r b534125f8baf src/lib-storage/list/mailbox-list-index.c
--- a/src/lib-storage/list/mailbox-list-index.c Wed Oct 22 14:15:23 2014 -0700
+++ b/src/lib-storage/list/mailbox-list-index.c Thu Oct 23 03:10:12 2014 +0300
@@ -169,15 +169,18 @@
static int mailbox_list_index_parse_header(struct mailbox_list_index *ilist,
struct mail_index_view *view)
{
- const void *data, *p;
+ const void *data, *name_start, *p;
size_t i, len, size;
uint32_t id, prev_id = 0;
+ string_t *str;
char *name;
+ int ret = 0;
mail_index_map_get_header_ext(view, view->map, ilist->ext_id, &data, &size);
if (size == 0)
return 0;
+ str = t_str_new(128);
for (i = sizeof(struct mailbox_list_index_header); i < size; ) {
/* get id */
if (i + sizeof(id) > size)
@@ -195,11 +198,18 @@
p = memchr(CONST_PTR_OFFSET(data, i), '\0', size-i);
if (p == NULL)
return -1;
- len = (const char *)p -
- (const char *)(CONST_PTR_OFFSET(data, i));
+ name_start = CONST_PTR_OFFSET(data, i);
+ len = (const char *)p - (const char *)name_start;
- name = p_strndup(ilist->mailbox_pool,
- CONST_PTR_OFFSET(data, i), len);
+ if (uni_utf8_get_valid_data(name_start, len, str)) {
+ name = p_strndup(ilist->mailbox_pool, name_start, len);
+ } else {
+ /* corrupted index. fix the name. */
+ name = p_strdup(ilist->mailbox_pool, str_c(str));
+ str_truncate(str, 0);
+ ret = -1;
+ }
+
i += len + 1;
/* add id => name to hash table */
@@ -207,7 +217,7 @@
ilist->highest_name_id = id;
}
i_assert(i == size);
- return 0;
+ return ret;
}
static void
More information about the dovecot-cvs
mailing list