]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix issues in SPF macros parsing rspamd-1.5
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 6 Jun 2017 11:17:54 +0000 (12:17 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 6 Jun 2017 11:18:29 +0000 (12:18 +0100)
src/libserver/spf.c

index fdd4a5136b75ad3b300197d97f1776d4c4b3703f..d985695fcb42d49acc2f94090d38db00a4f27901 100644 (file)
@@ -1386,7 +1386,7 @@ reverse_spf_ip (gchar *ip, gint len)
 }
 
 static const gchar *
-expand_spf_macro (struct spf_record *rec,
+expand_spf_macro (struct spf_record *rec, struct spf_resolved_element *resolved,
                const gchar *begin)
 {
        const gchar *p;
@@ -1396,13 +1396,11 @@ expand_spf_macro (struct spf_record *rec,
        gchar ip_buf[INET6_ADDRSTRLEN];
        gboolean need_expand = FALSE;
        struct rspamd_task *task;
-       struct spf_resolved_element *resolved;
 
        g_assert (rec != NULL);
        g_assert (begin != NULL);
 
        task = rec->task;
-       resolved = g_ptr_array_index (rec->resolved, rec->resolved->len - 1);
        p = begin;
        /* Calculate length */
        while (*p) {
@@ -1594,8 +1592,14 @@ expand_spf_macro (struct spf_record *rec,
                                                c += len;
                                                break;
                                        case 'v':
-                                               len = sizeof ("in-addr") - 1;
-                                               memcpy (c, "in-addr", len);
+                                               if (rspamd_inet_address_get_af (task->from_addr) == AF_INET) {
+                                                       len = sizeof ("in-addr") - 1;
+                                                       memcpy (c, "in-addr", len);
+                                               }
+                                               else {
+                                                       len = sizeof ("ip6") - 1;
+                                                       memcpy (c, "ip6", len);
+                                               }
                                                c += len;
                                                break;
                                        case 'h':
@@ -1606,6 +1610,11 @@ expand_spf_macro (struct spf_record *rec,
                                                                memcpy (c, tmp + 1, len);
                                                                c += len;
                                                        }
+                                                       else {
+                                                               len = strlen (task->helo);
+                                                               memcpy (c, task->helo, len);
+                                                               c += len;
+                                                       }
                                                }
                                                break;
                                        default:
@@ -1671,7 +1680,7 @@ parse_spf_record (struct spf_record *rec, struct spf_resolved_element *resolved,
        }
 
        task = rec->task;
-       begin = expand_spf_macro (rec, elt);
+       begin = expand_spf_macro (rec, resolved, elt);
        addr = rspamd_spf_new_addr (rec, resolved, begin);
        g_assert (addr != NULL);
        t = g_ascii_tolower (addr->spf_string[0]);