]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Fix dkim length parsing.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 2 Oct 2014 22:36:08 +0000 (23:36 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 2 Oct 2014 22:36:08 +0000 (23:36 +0100)
src/libserver/dkim.c
src/rdns

index 6bf9f90f6a1a2c472ee02b33aa3502ee9c3bb171..f0a325a06df6e54acc56fcbea7bcbfb784278496 100644 (file)
@@ -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;
        }
index 8d80ac78cf6436c077804dd0972866a5bd55732f..a21b4c0afc2c4bd7a2a16fbd6ba05033c926f6c2 160000 (submodule)
--- a/src/rdns
+++ b/src/rdns
@@ -1 +1 @@
-Subproject commit 8d80ac78cf6436c077804dd0972866a5bd55732f
+Subproject commit a21b4c0afc2c4bd7a2a16fbd6ba05033c926f6c2