commit 2197686: [Minor] Try to support rewritten from in dkim signing

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Apr 4 09:21:03 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-04-04 10:16:48 +0100
URL: https://github.com/rspamd/rspamd/commit/2197686e13fcdd3b6d330961033a0b6c04943176

[Minor] Try to support rewritten from in dkim signing

---
 src/libserver/dkim.c | 29 +++++++++++++++++++++++++++++
 src/lua/lua_task.c   |  7 +++++--
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/src/libserver/dkim.c b/src/libserver/dkim.c
index 8100f8ee3..9f5cabf6e 100644
--- a/src/libserver/dkim.c
+++ b/src/libserver/dkim.c
@@ -106,6 +106,7 @@ struct rspamd_dkim_common_ctx {
 	gsize len;
 	gint header_canon_type;
 	gint body_canon_type;
+	gboolean is_sign;
 	GPtrArray *hlist;
 	GHashTable *htable; /* header -> count mapping */
 	EVP_MD_CTX *headers_hash;
@@ -2195,6 +2196,33 @@ rspamd_dkim_canonize_header (struct rspamd_dkim_common_ctx *ctx,
 						(gint)rh->raw_len, rh->raw_value);
 			}
 			else {
+				if (ctx->is_sign && (rh->type & RSPAMD_HEADER_FROM)) {
+					/* Special handling of the From handling when rewrite is done */
+					gboolean has_rewrite = FALSE;
+					guint i;
+					struct rspamd_email_address *addr;
+
+					PTR_ARRAY_FOREACH (task->from_mime, i, addr) {
+						if ((addr->flags & RSPAMD_EMAIL_ADDR_ORIGINAL)
+							&& !(addr->flags & RSPAMD_EMAIL_ADDR_ALIASED)) {
+							has_rewrite = TRUE;
+						}
+					}
+
+					if (has_rewrite) {
+						PTR_ARRAY_FOREACH (task->from_mime, i, addr) {
+							if (!(addr->flags & RSPAMD_EMAIL_ADDR_ORIGINAL)) {
+								if (!rspamd_dkim_canonize_header_relaxed (ctx, addr->raw,
+										header_name, FALSE)) {
+									return FALSE;
+								}
+
+								return TRUE;
+							}
+						}
+					}
+				}
+
 				if (!rspamd_dkim_canonize_header_relaxed (ctx, rh->value,
 						header_name, FALSE)) {
 					return FALSE;
@@ -2842,6 +2870,7 @@ rspamd_create_dkim_sign_context (struct rspamd_task *task,
 	nctx->common.header_canon_type = headers_canon;
 	nctx->common.body_canon_type = body_canon;
 	nctx->common.type = type;
+	nctx->common.is_sign = TRUE;
 
 	if (type != RSPAMD_DKIM_ARC_SEAL) {
 		if (!rspamd_dkim_parse_hdrlist_common (&nctx->common, headers,
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index d8ba74ec0..ad11f2b41 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -2906,10 +2906,13 @@ lua_import_email_address (lua_State *L, struct rspamd_task *task,
 	lua_gettable (L, pos);
 
 	if (lua_type (L, -1) == LUA_TSTRING) {
+		gchar *cpy;
 		p = lua_tolstring (L, -1, &len);
-		addr->raw = (const gchar *)rspamd_mempool_alloc (task->task_pool, len);
-		memcpy ((gchar *)addr->raw, p, len);
+		cpy = rspamd_mempool_alloc (task->task_pool, len + 1);
+		memcpy (cpy, p, len);
+		cpy[len] = '\0';
 		addr->raw_len = len;
+		addr->raw = cpy;
 	}
 	else {
 		/* Construct raw addr */


More information about the Commits mailing list