summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-06-06 12:17:54 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-06-06 12:18:11 +0100
commitcfcfee6e154a7f6a833d329dbe4d93e7320f7862 (patch)
tree13323e4e4d3fba8bde301a95b446b475a1865dcf /src
parentad2f46d5aef3b238a12a87fcd8ff428f4b97bdf7 (diff)
downloadrspamd-cfcfee6e154a7f6a833d329dbe4d93e7320f7862.tar.gz
rspamd-cfcfee6e154a7f6a833d329dbe4d93e7320f7862.zip
[Fix] Fix issues in SPF macros parsing
Diffstat (limited to 'src')
-rw-r--r--src/libserver/spf.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/libserver/spf.c b/src/libserver/spf.c
index 2bbb737eb..13877ed31 100644
--- a/src/libserver/spf.c
+++ b/src/libserver/spf.c
@@ -1387,7 +1387,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;
@@ -1397,13 +1397,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) {
@@ -1595,8 +1593,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':
@@ -1607,6 +1611,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:
@@ -1672,7 +1681,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]);