diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-10-02 23:36:08 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-10-02 23:36:08 +0100 |
commit | 6d27e3eda3e809248dbca506bf8eb96543df641c (patch) | |
tree | b866931b32cb902212eed2bc9a0ffb94184d89b2 | |
parent | 6f8fa405cf5d394491b987d824f5e1b74c14a4c8 (diff) | |
download | rspamd-6d27e3eda3e809248dbca506bf8eb96543df641c.tar.gz rspamd-6d27e3eda3e809248dbca506bf8eb96543df641c.zip |
Fix dkim length parsing.
-rw-r--r-- | src/libserver/dkim.c | 44 | ||||
m--------- | src/rdns | 0 |
2 files changed, 22 insertions, 22 deletions
diff --git a/src/libserver/dkim.c b/src/libserver/dkim.c index 6bf9f90f6..f0a325a06 100644 --- a/src/libserver/dkim.c +++ b/src/libserver/dkim.c @@ -1018,7 +1018,8 @@ rspamd_get_dkim_key (rspamd_dkim_context_t *ctx, } static gboolean -rspamd_dkim_relaxed_body_step (GChecksum *ck, const gchar **start, guint remain) +rspamd_dkim_relaxed_body_step (GChecksum *ck, const gchar **start, guint size, + guint *remain) { const gchar *h; static gchar buf[BUFSIZ]; @@ -1026,11 +1027,11 @@ rspamd_dkim_relaxed_body_step (GChecksum *ck, const gchar **start, guint remain) guint len, inlen; gboolean got_sp, finished = FALSE; - if (remain > sizeof (buf)) { + if (size > sizeof (buf)) { len = sizeof (buf); } else { - len = remain; + len = size; finished = TRUE; } inlen = sizeof (buf) - 1; @@ -1097,13 +1098,18 @@ rspamd_dkim_relaxed_body_step (GChecksum *ck, const gchar **start, guint remain) #if 0 msg_debug ("update signature with buffer: %*s", t - buf, buf); #endif - g_checksum_update (ck, buf, t - buf); + if (*remain > 0) { + size_t cklen = MIN(t - buf, *remain); + g_checksum_update (ck, buf, cklen); + *remain = *remain - cklen; + } return !finished; } static gboolean -rspamd_dkim_simple_body_step (GChecksum *ck, const gchar **start, guint remain) +rspamd_dkim_simple_body_step (GChecksum *ck, const gchar **start, guint size, + guint *remain) { const gchar *h; static gchar buf[BUFSIZ]; @@ -1111,11 +1117,11 @@ rspamd_dkim_simple_body_step (GChecksum *ck, const gchar **start, guint remain) guint len, inlen; gboolean finished = FALSE; - if (remain > sizeof (buf)) { + if (size > sizeof (buf)) { len = sizeof (buf); } else { - len = remain; + len = size; finished = TRUE; } inlen = sizeof (buf) - 1; @@ -1153,7 +1159,11 @@ rspamd_dkim_simple_body_step (GChecksum *ck, const gchar **start, guint remain) #if 0 msg_debug ("update signature with buffer: %*s", t - buf, buf); #endif - g_checksum_update (ck, buf, t - buf); + if (*remain > 0) { + size_t cklen = MIN(t - buf, *remain); + g_checksum_update (ck, buf, cklen); + *remain = *remain - cklen; + } return !finished; } @@ -1164,6 +1174,7 @@ rspamd_dkim_canonize_body (rspamd_dkim_context_t *ctx, const gchar *end) { const gchar *p; + guint remain = ctx->len ? ctx->len : end - start; if (start == NULL) { /* Empty body */ @@ -1205,11 +1216,11 @@ rspamd_dkim_canonize_body (rspamd_dkim_context_t *ctx, if (ctx->body_canon_type == DKIM_CANON_SIMPLE) { /* Simple canonization */ while (rspamd_dkim_simple_body_step (ctx->body_hash, &start, - end - start)) ; + end - start, &remain)) ; } else { while (rspamd_dkim_relaxed_body_step (ctx->body_hash, &start, - end - start)) ; + end - start, &remain)) ; } } return TRUE; @@ -1674,18 +1685,7 @@ rspamd_dkim_check (rspamd_dkim_context_t *ctx, } /* Start canonization of body part */ - if (headers_end) { - if (ctx->len == 0 || (gint)ctx->len > end - headers_end) { - body_end = end; - } - else { - /* Strip message */ - body_end = headers_end + ctx->len; - } - } - else { - body_end = end; - } + body_end = end; if (!rspamd_dkim_canonize_body (ctx, headers_end, body_end)) { return DKIM_RECORD_ERROR; } diff --git a/src/rdns b/src/rdns -Subproject 8d80ac78cf6436c077804dd0972866a5bd55732 +Subproject a21b4c0afc2c4bd7a2a16fbd6ba05033c926f6c |