]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: smtp-server-reply - Fix smtp_server_reply_replace_path() to update last...
authorStephan Bosch <stephan.bosch@open-xchange.com>
Tue, 15 Aug 2023 22:59:21 +0000 (00:59 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 29 Aug 2023 12:52:24 +0000 (12:52 +0000)
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 <path> 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

index 2ded9a8dd76a199c53227e2254d461271926fac3..97b2d08c34d2497b45917a999f8dde7c2a085666 100644 (file)
@@ -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);
        }
 }