diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-08-22 15:23:49 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-08-22 15:29:40 +0100 |
commit | 2a1876dd1c2e1e8df19a002f97d4cc2fc2216328 (patch) | |
tree | d8541c55ae39f17f871c7c88280a21428d625e8c | |
parent | 6fde333aeee50108222673b16e28d81a09efe943 (diff) | |
download | rspamd-2a1876dd1c2e1e8df19a002f97d4cc2fc2216328.tar.gz rspamd-2a1876dd1c2e1e8df19a002f97d4cc2fc2216328.zip |
[Fix] Fix some border cases for DKIM canonicalization
Issue: #880
-rw-r--r-- | src/libserver/dkim.c | 75 |
1 files changed, 47 insertions, 28 deletions
diff --git a/src/libserver/dkim.c b/src/libserver/dkim.c index 51f366179..d38fe6cb1 100644 --- a/src/libserver/dkim.c +++ b/src/libserver/dkim.c @@ -1316,7 +1316,7 @@ rspamd_dkim_skip_empty_lines (const gchar *start, const gchar *end, } state = init; guint skip = 0; - while (p >= start + 2) { + while (p >= start + 1) { switch (state) { case init: if (*p == '\r') { @@ -1353,44 +1353,60 @@ rspamd_dkim_skip_empty_lines (const gchar *start, const gchar *end, } break; case got_cr: - if (*(p - 1) == '\r') { - p --; - state = got_cr; - } - else if (*(p - 1) == '\n') { - if ((*p - 2) == '\r') { - /* \r\n\r -> we know about one line */ - p -= 1; - state = got_crlf; + if (p > start - 1) { + if (*(p - 1) == '\r') { + p --; + state = got_cr; + } + else if (*(p - 1) == '\n') { + if ((*p - 2) == '\r') { + /* \r\n\r -> we know about one line */ + p -= 1; + state = got_crlf; + } + else { + /* \n\r -> we know about one line */ + p -= 1; + state = got_lf; + } + } + else if (type == DKIM_CANON_RELAXED && *(p - 1) == ' ') { + skip = 1; + state = test_spaces; } else { - /* \n\r -> we know about one line */ - p -= 1; - state = got_lf; + goto end; } } - else if (type == DKIM_CANON_RELAXED && *(p - 1) == ' ') { - skip = 1; - state = test_spaces; - } else { + if (type == DKIM_CANON_RELAXED) { + p -= 1; + } goto end; } break; case got_lf: - if (*(p - 1) == '\r') { - state = got_crlf; - } - else if (*(p - 1) == '\n') { - /* We know about one line */ - p --; - state = got_lf; - } - else if (type == DKIM_CANON_RELAXED && *(p - 1) == ' ') { - skip = 1; - state = test_spaces; + if (p > start - 1) { + if (*(p - 1) == '\r') { + state = got_crlf; + } + else if (*(p - 1) == '\n') { + /* We know about one line */ + p --; + state = got_lf; + } + else if (type == DKIM_CANON_RELAXED && *(p - 1) == ' ') { + skip = 1; + state = test_spaces; + } + else { + goto end; + } } else { + if (type == DKIM_CANON_RELAXED) { + p -= 1; + } goto end; } break; @@ -1413,6 +1429,9 @@ rspamd_dkim_skip_empty_lines (const gchar *start, const gchar *end, } } else { + if (type == DKIM_CANON_RELAXED) { + p -= 2; + } goto end; } break; |