]> 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@open-xchange.com>
Wed, 26 Sep 2018 10:52:28 +0000 (10:52 +0000)
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 45fc77c7e5f9e45a74882cdc97ec5de9fad0f803..fd9de94d7ebe37c6e3e596dbd51780f74b869dbf 100644 (file)
@@ -1098,8 +1098,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);
        }
 
@@ -1232,6 +1234,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 57a0229c7d6b1ff1a90618e53c8e6cf752ba5192..4f9c02dc26f5c6bd81c7421eb37e2d23e85ffd40 100644 (file)
@@ -166,6 +166,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;