diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-10-08 10:39:59 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-10-08 10:39:59 +0100 |
commit | 8a4c1dc178012f04fe1590e74c134af2492ba180 (patch) | |
tree | 5d266f92e659a269f6795b9152c7a459bcf4e900 /src/libmime/received.cxx | |
parent | b8c0ebc33440fe15216a4369c73faa1951e6b244 (diff) | |
download | rspamd-8a4c1dc178012f04fe1590e74c134af2492ba180.tar.gz rspamd-8a4c1dc178012f04fe1590e74c134af2492ba180.zip |
[Minor] Restore compatible behaviour for incomplete received headers
Diffstat (limited to 'src/libmime/received.cxx')
-rw-r--r-- | src/libmime/received.cxx | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/libmime/received.cxx b/src/libmime/received.cxx index 836af0464..0ff52da5a 100644 --- a/src/libmime/received.cxx +++ b/src/libmime/received.cxx @@ -263,13 +263,6 @@ received_spill(const std::string_view &in, auto len = end - p; - /* Ignore all received but those started from from part */ - if (len <= 4 || !lit_compare_lowercase<4>("from", p)) { - return {}; - } - - p += sizeof("from") - 1; - auto maybe_process_part = [&](received_part_type what) -> bool { parts.emplace_back(what); auto &rcvd_part = parts.back(); @@ -284,14 +277,19 @@ received_spill(const std::string_view &in, return true; }; - /* We can now store from part */ - if (!maybe_process_part(received_part_type::RSPAMD_RECEIVED_PART_FROM)) { - return {}; - } + if (len > 4 && lit_compare_lowercase<4>("from", p)) { + p += sizeof("from") - 1; - g_assert (pos != 0); - p += pos; - len = end > p ? end - p : 0; + /* We can now store from part */ + if (!maybe_process_part(received_part_type::RSPAMD_RECEIVED_PART_FROM)) { + /* Do not accept malformed from */ + return {}; + } + + g_assert (pos != 0); + p += pos; + len = end > p ? end - p : 0; + } if (len > 2 && lit_compare_lowercase<2>("by", p)) { p += sizeof("by") - 1; @@ -991,6 +989,12 @@ TEST_CASE("parse received") {"from_hostname", "smtp11.mailtrack.pl"} } }, + // No from part + {"by mail.832zsu.cn (Postfix) with ESMTPA id AAD722133E34"sv, + { + {"by_hostname", "mail.832zsu.cn"}, + } + }, }; rspamd_mempool_t *pool = rspamd_mempool_new_default("rcvd test", 0); |