@@ -618,15 +618,19 @@ BOOL exmdb_server::recalc_store_size(const char *dir, uint32_t flags)
618618 return sql_transact.commit () == SQLITE_OK ? TRUE : false ;
619619}
620620
621- static bool imapfile_type_ok (const std::string &s )
621+ static bool imapfile_name_ok (const std::string &type, const std::string &mid )
622622{
623- return s == " eml" || s == " ext" || s == " tmp/imap.rfc822" ;
623+ if (mid.empty () || mid[0 ] == ' .' || mid.find (" /." ) != mid.npos )
624+ return false ;
625+ if (type != " eml" && type != " ext" && type != " tmp/imap.rfc822" )
626+ return false ;
627+ return true ;
624628}
625629
626630BOOL exmdb_server::imapfile_read (const char *dir, const std::string &type,
627631 const std::string &mid, std::string *data)
628632{
629- if (!imapfile_type_ok (type) || mid. find ( ' / ' ) != mid. npos )
633+ if (!imapfile_name_ok (type, mid) )
630634 return false ;
631635 size_t slurp_size = 0 ;
632636 std::unique_ptr<char [], stdlib_delete> slurp_data (HX_slurp_file ((dir + " /" s + type + " /" + mid).c_str (), &slurp_size));
@@ -639,7 +643,7 @@ BOOL exmdb_server::imapfile_read(const char *dir, const std::string &type,
639643BOOL exmdb_server::imapfile_write (const char *dir, const std::string &type,
640644 const std::string &mid, const std::string &data)
641645{
642- if (!imapfile_type_ok (type) || mid. find ( ' / ' ) != mid. npos )
646+ if (!imapfile_name_ok (type, mid) )
643647 return false ;
644648 gromox::tmpfile tf;
645649 auto fd = tf.open_linkable (dir, O_WRONLY, FMODE_PRIVATE);
@@ -660,7 +664,7 @@ BOOL exmdb_server::imapfile_write(const char *dir, const std::string &type,
660664BOOL exmdb_server::imapfile_delete (const char *dir, const std::string &type,
661665 const std::string &mid)
662666{
663- if (!imapfile_type_ok (type) || mid. find ( ' / ' ) != mid. npos )
667+ if (!imapfile_name_ok (type, mid) )
664668 return false ;
665669 auto fn = dir + " /" s + type + " /" + mid;
666670 if (remove (fn.c_str ()) < 0 && errno != ENOENT) {
0 commit comments