Skip to content

Commit

Permalink
lib-smtp: client: Make the initialization of the connection after SSL…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
stephanbosch authored and cmouse committed Sep 28, 2018
1 parent 1b5e381 commit c4f8ab0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib-smtp/smtp-client-connection.c
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/lib-smtp/smtp-client-private.h
Expand Up @@ -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;
Expand Down

0 comments on commit c4f8ab0

Please sign in to comment.