From 8a4c1dc178012f04fe1590e74c134af2492ba180 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 8 Oct 2021 10:39:59 +0100 Subject: [PATCH] [Minor] Restore compatible behaviour for incomplete received headers --- src/libmime/received.cxx | 32 ++++++++++++++++++-------------- 1 file 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); -- 2.39.5