]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: mail_cache_*_fields - Log an error if hdr.<name> isn't valid
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 14 Apr 2020 09:24:50 +0000 (12:24 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Fri, 23 Jul 2021 16:16:43 +0000 (16:16 +0000)
Mainly verify that it doesn't have accidental UTF-8 characters that aren't
easily visible in text editors.

src/lib-storage/index/index-storage.c

index 82d721f97cf63b619dcacb35396f7aac9a058681..757284661c8abd81e8f55924a4b86f7c0caca26a 100644 (file)
@@ -9,6 +9,7 @@
 #include "str-sanitize.h"
 #include "mkdir-parents.h"
 #include "dict.h"
+#include "message-header-parser.h"
 #include "mail-index-alloc-cache.h"
 #include "mail-index-private.h"
 #include "mail-index-modseq.h"
@@ -48,9 +49,19 @@ static void set_cache_decisions(struct mail_cache *cache,
                if (idx != UINT_MAX) {
                        field = *mail_cache_register_get_field(cache, idx);
                } else if (strncasecmp(name, "hdr.", 4) == 0) {
-                       i_zero(&field);
-                       field.name = name;
-                       field.type = MAIL_CACHE_FIELD_HEADER;
+                       /* Do some sanity checking for the header name. Mainly
+                          to make sure there aren't UTF-8 characters that look
+                          like their ASCII equivalents or are completely
+                          invisible. */
+                       if (message_header_name_is_valid(name+4)) {
+                               i_zero(&field);
+                               field.name = name;
+                               field.type = MAIL_CACHE_FIELD_HEADER;
+                       } else {
+                               i_error("%s: Header name '%s' has invalid character, ignoring",
+                                       set, name);
+                               continue;
+                       }
                } else {
                        i_error("%s: Unknown cache field name '%s', ignoring",
                                set, *arr);