]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Filter bad characters from message id
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 8 Feb 2017 13:38:50 +0000 (13:38 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 8 Feb 2017 13:46:57 +0000 (13:46 +0000)
Issue: #1403

src/libmime/mime_headers.c

index 282579548b286971f68e3ef7a21d8a49b2c67e19..35c13d1f3a460754fe15c9cb6bdc05e3f85f797e 100644 (file)
@@ -28,6 +28,8 @@ rspamd_mime_header_check_special (struct rspamd_task *task,
 {
        guint64 h;
        struct received_header *recv;
+       const gchar *p, *end;
+       gchar *id;
 
        h = rspamd_icase_hash (rh->name, strlen (rh->name), 0xdeadbabe);
 
@@ -56,7 +58,6 @@ rspamd_mime_header_check_special (struct rspamd_task *task,
                                rh->value, strlen (rh->value), task->from_mime);
                break;
        case 0x43A558FC7C240226ULL:     /* message-id */ {
-               gchar *p, *end;
 
                p = rh->decoded;
                end = p + strlen (p);
@@ -64,14 +65,32 @@ rspamd_mime_header_check_special (struct rspamd_task *task,
                if (*p == '<') {
                        p ++;
 
-                       if (end > p && *(end - 1) == '>') {
-                               *(end - 1) = '\0';
-                               p = rspamd_mempool_strdup (task->task_pool, p);
-                               *(end - 1) = '>';
+                       if (end > p) {
+                               gchar *d;
+
+                               if (*(end - 1) == '>') {
+                                       end --;
+                               }
+
+                               id = rspamd_mempool_alloc (task->task_pool, end - p + 1);
+                               d = id;
+
+                               while (p < end) {
+                                       if (g_ascii_isgraph (*p)) {
+                                               *d++ = *p++;
+                                       }
+                                       else {
+                                               *d++ = '?';
+                                               p++;
+                                       }
+                               }
+
+                               *d = '\0';
+
+                               task->message_id = id;
                        }
                }
 
-               task->message_id = p;
                break;
        }
        case 0xB91D3910358E8212ULL:     /* subject */