]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fix multiple headers in DKIM headers list
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 21 Oct 2017 14:52:50 +0000 (15:52 +0100)
committerAndrew Lewis <nerf@judo.za.org>
Sat, 21 Oct 2017 19:03:22 +0000 (21:03 +0200)
MFH: rspamd-1.6
Issue: #1876

src/libserver/dkim.c

index 2b53571451ef9c6e2e08d26f260b9d58d7bfce88..83b4bc713c1ae6e729d286ad6a3877f3ec8a5eb6 100644 (file)
@@ -394,6 +394,7 @@ rspamd_dkim_parse_hdrlist_common (struct rspamd_dkim_common_ctx *ctx,
        gboolean from_found = FALSE;
        guint count = 0;
        struct rspamd_dkim_header *new;
+       gpointer found;
        GHashTable *htb;
 
        p = param;
@@ -417,30 +418,37 @@ rspamd_dkim_parse_hdrlist_common (struct rspamd_dkim_common_ctx *ctx,
 
        while (p <= end) {
                if ((p == end || *p == ':') && p - c > 0) {
+
                        h = rspamd_mempool_alloc (ctx->pool, p - c + 1);
                        rspamd_strlcpy (h, c, p - c + 1);
-                       g_strstrip (h);
 
-                       new = rspamd_mempool_alloc (ctx->pool,
-                                       sizeof (struct rspamd_dkim_header));
-                       new->name = h;
-                       new->count = 0;
+                       g_strstrip (h);
 
                        /* Check mandatory from */
                        if (!from_found && g_ascii_strcasecmp (h, "from") == 0) {
                                from_found = TRUE;
                        }
 
+                       new = rspamd_mempool_alloc (ctx->pool,
+                                       sizeof (struct rspamd_dkim_header));
+                       new->name = h;
+                       new->count = 0;
+
                        g_ptr_array_add (ctx->hlist, new);
 
-                       if (g_hash_table_lookup (htb, h) != NULL) {
-                               new->count++;
+                       if ((found = g_hash_table_lookup (htb, h)) != NULL) {
+                               count = GPOINTER_TO_UINT (found);
+                               new->count = count;
+                               count ++;
+                               g_hash_table_insert (htb, h, GUINT_TO_POINTER (count));
                        }
                        else {
-                               /* Insert new header to the list */
-                               g_hash_table_insert (htb, (gpointer)new->name, new);
+                               /* Insert new header order to the list */
+                               count = new->count + 1;
                        }
 
+                       g_hash_table_insert (htb, h, GUINT_TO_POINTER (count));
+
                        c = p + 1;
                        p++;
                }