# HG changeset patch # User Timo Sirainen # Date 1139144620 -7200 # Node ID 882ec6cc59706be2b5c153feaf3571adc2064d5c # Parent 565e3040a9f50dccb2d03309f80a6fabbcba1842 Limit maximum mailbox name length while creating them. diff -r 565e3040a9f5 -r 882ec6cc5970 src/lib-storage/index/dbox/dbox-storage.c --- a/src/lib-storage/index/dbox/dbox-storage.c Sun Feb 05 14:59:01 2006 +0200 +++ b/src/lib-storage/index/dbox/dbox-storage.c Sun Feb 05 15:03:40 2006 +0200 @@ -18,6 +18,10 @@ #define CREATE_MODE 0770 /* umask() should limit it more */ +/* Don't allow creating too long mailbox names. They could start causing + problems when they reach the limit. */ +#define DBOX_MAX_MAILBOX_NAME_LENGTH (PATH_MAX/2) + struct rename_context { bool found; size_t oldnamelen; @@ -178,7 +182,8 @@ len = strlen(name); if (name[0] == '\0' || name[len-1] == '/' || - strchr(name, '*') != NULL || strchr(name, '%') != NULL) + strchr(name, '*') != NULL || strchr(name, '%') != NULL || + len > DBOX_MAX_MAILBOX_NAME_LENGTH) return FALSE; return dbox_is_valid_mask(storage, name); diff -r 565e3040a9f5 -r 882ec6cc5970 src/lib-storage/index/maildir/maildir-storage.c --- a/src/lib-storage/index/maildir/maildir-storage.c Sun Feb 05 14:59:01 2006 +0200 +++ b/src/lib-storage/index/maildir/maildir-storage.c Sun Feb 05 15:03:40 2006 +0200 @@ -18,6 +18,10 @@ #define CREATE_MODE 0770 /* umask() should limit it more */ +/* Don't allow creating too long mailbox names. They could start causing + problems when they reach the limit. */ +#define MAILDIR_MAX_MAILBOX_NAME_LENGTH (PATH_MAX/2) + struct rename_context { bool found; size_t oldnamelen; @@ -179,8 +183,8 @@ size_t len; len = strlen(name); - if (len == 0 || name[0] == MAILDIR_FS_SEP || - name[len-1] == MAILDIR_FS_SEP || + if (len == 0 || len > MAILDIR_MAX_MAILBOX_NAME_LENGTH || + name[0] == MAILDIR_FS_SEP || name[len-1] == MAILDIR_FS_SEP || strchr(name, '*') != NULL || strchr(name, '%') != NULL) return FALSE; diff -r 565e3040a9f5 -r 882ec6cc5970 src/lib-storage/index/mbox/mbox-storage.c --- a/src/lib-storage/index/mbox/mbox-storage.c Sun Feb 05 14:59:01 2006 +0200 +++ b/src/lib-storage/index/mbox/mbox-storage.c Sun Feb 05 15:03:40 2006 +0200 @@ -22,6 +22,10 @@ #define CREATE_MODE 0770 /* umask() should limit it more */ +/* Don't allow creating too long mailbox names. They could start causing + problems when they reach the limit. */ +#define MBOX_MAX_MAILBOX_NAME_LENGTH (PATH_MAX/2) + /* NOTE: must be sorted for istream-header-filter. Note that it's not such a good idea to change this list, as the messages will then change from client's point of view. So if you do it, change all mailboxes' UIDVALIDITY @@ -384,7 +388,8 @@ len = strlen(name); if (name[0] == '\0' || name[len-1] == '/' || - strchr(name, '*') != NULL || strchr(name, '%') != NULL) + strchr(name, '*') != NULL || strchr(name, '%') != NULL || + len > MBOX_MAX_MAILBOX_NAME_LENGTH) return FALSE; return mbox_is_valid_mask(storage, name);