From c4187679948bc97445477cfc825ccdeecb5150bd Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 8 Mar 2019 15:16:01 +0000 Subject: [PATCH] [Fix] Ignore whitespaces at the end of value in DKIM records --- src/libserver/dkim.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/libserver/dkim.c b/src/libserver/dkim.c index 129d78c9c..8f41d6220 100644 --- a/src/libserver/dkim.c +++ b/src/libserver/dkim.c @@ -971,15 +971,31 @@ rspamd_create_dkim_context (const gchar *sig, case DKIM_STATE_VALUE: if (*p == ';') { if (param == DKIM_PARAM_UNKNOWN || - p - c == 0 || - !parser_funcs[param](ctx, c, p - c, err)) { + p - c == 0) { state = DKIM_STATE_ERROR; } else { - state = DKIM_STATE_SKIP_SPACES; - next_state = DKIM_STATE_TAG; - p++; - taglen = 0; + /* Cut trailing spaces for value */ + gint tlen = p - c; + const gchar *tmp = p - 1; + + while (tlen > 0) { + if (!g_ascii_isspace (*tmp)) { + break; + } + tlen --; + tmp --; + } + + if (!parser_funcs[param](ctx, c, tlen, err)) { + state = DKIM_STATE_ERROR; + } + else { + state = DKIM_STATE_SKIP_SPACES; + next_state = DKIM_STATE_TAG; + p++; + taglen = 0; + } } } else if (p == end) { -- 2.39.5