]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: mail_cache_*_fields - Check for invalid header names while parsing config
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 21 Jul 2021 15:12:36 +0000 (18:12 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Fri, 23 Jul 2021 16:16:43 +0000 (16:16 +0000)
This way the errors are noticed early on.

src/config/settings-get.pl
src/lib-storage/mail-storage-settings.c

index 644b9b5e64f500d0023bd866c5ace8f859f0ebf2..e900baaf7d17d96def838007c8ce41d3855f9417 100755 (executable)
@@ -20,6 +20,7 @@ print '#include "net.h"'."\n";
 print '#include "unichar.h"'."\n";
 print '#include "hash-method.h"'."\n";
 print '#include "settings-parser.h"'."\n";
+print '#include "message-header-parser.h"'."\n";
 print '#include "all-settings.h"'."\n";
 print '#include <stddef.h>'."\n";
 print '#include <unistd.h>'."\n";
index 0576262852e0a69ab4c254b25975f17898fdd57d..c9e5ce9c415cf3597b30b6f6f8c7eeb98861e899 100644 (file)
@@ -8,6 +8,7 @@
 #include "hostpid.h"
 #include "settings-parser.h"
 #include "message-address.h"
+#include "message-header-parser.h"
 #include "smtp-address.h"
 #include "mail-index.h"
 #include "mail-user.h"
@@ -433,6 +434,25 @@ fix_base_path(struct mail_user_settings *set, pool_t pool, const char **str)
 }
 
 /* <settings checks> */
+static bool mail_cache_fields_parse(const char *key, const char *value,
+                                   const char **error_r)
+{
+       const char *const *arr;
+
+       for (arr = t_strsplit_spaces(value, " ,"); *arr != NULL; arr++) {
+               const char *name = *arr;
+
+               if (strncasecmp(name, "hdr.", 4) == 0 &&
+                   !message_header_name_is_valid(name+4)) {
+                       *error_r = t_strdup_printf(
+                               "Invalid %s: %s is not a valid header name",
+                               key, name);
+                       return FALSE;
+               }
+       }
+       return TRUE;
+}
+
 static bool mail_storage_settings_check(void *_set, pool_t pool,
                                        const char **error_r)
 {
@@ -579,6 +599,15 @@ static bool mail_storage_settings_check(void *_set, pool_t pool,
                set->parsed_mail_attachment_content_type_filter = array_front(&content_types);
        }
 
+       if (!mail_cache_fields_parse("mail_cache_fields",
+                                    set->mail_cache_fields, error_r))
+               return FALSE;
+       if (!mail_cache_fields_parse("mail_always_cache_fields",
+                                    set->mail_always_cache_fields, error_r))
+               return FALSE;
+       if (!mail_cache_fields_parse("mail_never_cache_fields",
+                                    set->mail_never_cache_fields, error_r))
+               return FALSE;
        return TRUE;
 }