From: Stephan Bosch Date: Wed, 26 Sep 2018 10:25:59 +0000 (+0200) Subject: lib-smtp: client: Make the initialization of the connection after SSL handshake reliable. X-Git-Tag: 2.3.9~1384 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab2302b1200555ef68ec8e6e341962ee5d779de2;p=thirdparty%2Fdovecot%2Fcore.git lib-smtp: client: Make the initialization of the connection after SSL handshake reliable. 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. --- diff --git a/src/lib-smtp/smtp-client-connection.c b/src/lib-smtp/smtp-client-connection.c index 45fc77c7e5..fd9de94d7e 100644 --- a/src/lib-smtp/smtp-client-connection.c +++ b/src/lib-smtp/smtp-client-connection.c @@ -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); diff --git a/src/lib-smtp/smtp-client-private.h b/src/lib-smtp/smtp-client-private.h index 57a0229c7d..4f9c02dc26 100644 --- a/src/lib-smtp/smtp-client-private.h +++ b/src/lib-smtp/smtp-client-private.h @@ -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;