]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Restore compatible behaviour for incomplete received headers
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 8 Oct 2021 09:39:59 +0000 (10:39 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 8 Oct 2021 09:39:59 +0000 (10:39 +0100)
src/libmime/received.cxx

index 836af0464c1c316d19596f99f3394fdb99b9949b..0ff52da5a793e81aee6bc82dae76f44f1611927d 100644 (file)
@@ -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);