From 523098d15d99f4aec6f9fe0625f6f3738fdfc260 Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Wed, 16 Aug 2023 00:59:21 +0200 Subject: [PATCH] lib-smtp: smtp-server-reply - Fix smtp_server_reply_replace_path() to update last line offset. Before, the offset was not updated with the changes caused by replacing the path, causing a panic once the reply was sent: Panic: file smtp-server-reply.c: line 629 (smtp_server_reply_send_real): assertion failed: (text[0] == '-') This occurs when multi-line replies that involve a prefix before the reply message are being forwarded in a SMTP proxy/relay scenario (e.g. RCPT reply can have that). --- src/lib-smtp/smtp-server-reply.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib-smtp/smtp-server-reply.c b/src/lib-smtp/smtp-server-reply.c index 2ded9a8dd7..97b2d08c34 100644 --- a/src/lib-smtp/smtp-server-reply.c +++ b/src/lib-smtp/smtp-server-reply.c @@ -380,10 +380,17 @@ void smtp_server_reply_replace_path(struct smtp_server_reply *reply, path_text = smtp_address_encode_path(path); str_replace(reply->content->text, prefix_len, path_len, path_text); + if (reply->content->last_line > 0) { + i_assert(reply->content->last_line > path_len); + reply->content->last_line -= path_len; + reply->content->last_line += strlen(path_text); + } } else if (add) { path_text = t_strdup_printf( "<%s> ", smtp_address_encode(path)); str_insert(reply->content->text, prefix_len, path_text); + if (reply->content->last_line > 0) + reply->content->last_line += strlen(path_text); } } -- 2.47.3