]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: smtp-client-connection - Hold reference to command that is sending a stream.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Tue, 9 Feb 2021 22:35:53 +0000 (23:35 +0100)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Wed, 10 Mar 2021 11:17:50 +0000 (11:17 +0000)
This fixes a panic:

Panic: file smtp-client-command.c: line 715 (smtp_client_command_do_send_more): assertion failed: (cmd->stream != NULL)

src/lib-smtp/smtp-client-command.c
src/lib-smtp/smtp-client-connection.c

index 594db8acfb2612e837c2178cb33b2a512a6112ff..569fdd39e0ae09d8d2137afb2426e7b679e12f73 100644 (file)
@@ -131,6 +131,7 @@ bool smtp_client_command_unref(struct smtp_client_command **_cmd)
                conn->cmd_wait_list_count, conn->cmd_send_queue_count);
 
        i_assert(cmd->state >= SMTP_CLIENT_COMMAND_STATE_FINISHED);
+       i_assert(cmd != conn->cmd_streaming);
 
        i_stream_unref(&cmd->stream);
        event_unref(&cmd->event);
@@ -744,13 +745,18 @@ static int smtp_client_command_do_send_more(struct smtp_client_connection *conn)
                if (ret < 0)
                        return -1;
                e_debug(cmd->event, "Blocked while sending payload");
-               conn->cmd_streaming = cmd;
+               if (conn->cmd_streaming != cmd) {
+                       i_assert(conn->cmd_streaming == NULL);
+                       conn->cmd_streaming = cmd;
+                       smtp_client_command_ref(cmd);
+               }
                return 0;
        }
 
-       conn->cmd_streaming = NULL;
        conn->sending_command = FALSE;
-       smtp_client_command_sent(cmd);
+       if (conn->cmd_streaming != cmd ||
+           smtp_client_command_unref(&conn->cmd_streaming))
+               smtp_client_command_sent(cmd);
        return 1;
 }
 
index efbc3dfd758d80a15a48f7f19cbbd2c019b3549c..91f7e06a3a399d6d930254abe08a84b9fe079f3e 100644 (file)
@@ -1880,7 +1880,7 @@ void smtp_client_connection_disconnect(struct smtp_client_connection *conn)
                        conn, SMTP_CLIENT_COMMAND_ERROR_ABORTED,
                        "Disconnected from server");
        }
-       conn->cmd_streaming = NULL;
+       smtp_client_command_unref(&conn->cmd_streaming);
 }
 
 static struct smtp_client_connection *