]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: client: Make the initialization of the connection after SSL handshake reliable.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Wed, 26 Sep 2018 10:25:59 +0000 (12:25 +0200)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Fri, 28 Sep 2018 06:51:42 +0000 (09:51 +0300)
Before, the connection was not guaranteed to be fully initialized after the SSL
handshake. The problem would occur when the handshake finished while writing the
SSL output stream. In a similar HTTP client issue, this caused a segfault.

src/lib-smtp/smtp-client-connection.c
src/lib-smtp/smtp-client-private.h

index bbb67e2a1ae041bd0c5c40e9a49790bea0284dd2..3b5e0af28e70750a1a3dd583e828e50538e46c2f 100644 (file)
@@ -1003,8 +1003,10 @@ static void smtp_client_connection_input(struct connection *_conn)
                        i_assert(ret == 0);
                        return;
                }
+       }
 
-               /* ready for SMTP handshake */
+       if (!conn->connect_succeeded) {
+               /* just got ready for SMTP handshake */
                smtp_client_connection_established(conn);
        }
 
@@ -1137,6 +1139,9 @@ static void smtp_client_connection_destroy(struct connection *_conn)
 static void
 smtp_client_connection_established(struct smtp_client_connection *conn)
 {
+       i_assert(!conn->connect_succeeded);
+       conn->connect_succeeded = TRUE;
+
        if (conn->to_connect != NULL)
                timeout_reset(conn->to_connect);
 
index f70b2fd6848301c1319bd4d8f1a45b76a8930902..b0cbb5eeeb1bc40ae650f104aeefc61c30d6aa04 100644 (file)
@@ -163,6 +163,7 @@ struct smtp_client_connection {
        bool authenticated:1;
        bool initial_xclient_sent:1;
        bool connect_failed:1;
+       bool connect_succeeded:1;
        bool handshake_failed:1;
        bool corked:1;
        bool sent_quit:1;