diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-12-24 16:55:56 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-12-24 16:55:56 +0000 |
commit | 9131d16dfffbdf234e3c3aabccd6bdd8cbeea3c5 (patch) | |
tree | e6b151a2bfea5a801db0a099cb4c555f0ddc39f1 | |
parent | fabf4f1dfc5686fbf8cb6f9578ae55c2d86c0bf7 (diff) | |
download | rspamd-9131d16dfffbdf234e3c3aabccd6bdd8cbeea3c5.tar.gz rspamd-9131d16dfffbdf234e3c3aabccd6bdd8cbeea3c5.zip |
Fix dkim checks for relaxed body encoding.
-rw-r--r-- | src/dkim.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/src/dkim.c b/src/dkim.c index c65fb59fd..d864165ac 100644 --- a/src/dkim.c +++ b/src/dkim.c @@ -950,37 +950,51 @@ rspamd_dkim_simple_body_step (GChecksum *ck, const gchar **start, guint remain) static gboolean rspamd_dkim_canonize_body (rspamd_dkim_context_t *ctx, const gchar *start, const gchar *end) { + const gchar *p; + if (start == NULL) { /* Empty body */ - g_checksum_update (ctx->body_hash, CRLF, sizeof (CRLF) - 1); + if (ctx->body_canon_type == DKIM_CANON_SIMPLE) { + g_checksum_update (ctx->body_hash, CRLF, sizeof (CRLF) - 1); + } + else { + g_checksum_update (ctx->body_hash, "", 0); + } } else { - end --; - while (end > start + 2) { - if (*end == '\n' && *(end - 1) == '\r' && *(end - 2) == '\n') { - end -= 2; + /* Strip extra ending CRLF */ + p = end - 1; + while (p >= start + 2) { + if (*p == '\n' && *(p - 1) == '\r' && *(p - 2) == '\n') { + p -= 2; } - else if (*end == '\n' && *(end - 1) == '\n') { - end --; + else if (*p == '\n' && *(p - 1) == '\n') { + p --; } - else if (*end == '\r' && *(end - 1) == '\r') { - end --; + else if (*p == '\r' && *(p - 1) == '\r') { + p --; } else { break; } } + end = p + 1; if (end == start || end == start + 2) { /* Empty body */ - g_checksum_update (ctx->body_hash, CRLF, sizeof (CRLF) - 1); + if (ctx->body_canon_type == DKIM_CANON_SIMPLE) { + g_checksum_update (ctx->body_hash, CRLF, sizeof (CRLF) - 1); + } + else { + g_checksum_update (ctx->body_hash, "", 0); + } } else { if (ctx->body_canon_type == DKIM_CANON_SIMPLE) { /* Simple canonization */ - while (rspamd_dkim_simple_body_step (ctx->body_hash, &start, end - start + 1)); + while (rspamd_dkim_simple_body_step (ctx->body_hash, &start, end - start)); } else { - while (rspamd_dkim_relaxed_body_step (ctx->body_hash, &start, end - start + 1)); + while (rspamd_dkim_relaxed_body_step (ctx->body_hash, &start, end - start)); } } return TRUE; |