From: Stephan Bosch Date: Tue, 15 Aug 2023 22:59:21 +0000 (+0200) Subject: lib-smtp: smtp-server-reply - Fix smtp_server_reply_replace_path() to update last... X-Git-Tag: 2.4.0~2607 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=523098d15d99f4aec6f9fe0625f6f3738fdfc260;p=thirdparty%2Fdovecot%2Fcore.git 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). --- 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); } }