From 9d0640616c30701bed286034840facfb386db90e Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Tue, 17 Apr 2018 15:58:58 +0300 Subject: [PATCH] lib-ssl-iostream: Do not handshake further if we are destroying --- src/lib-ssl-iostream/iostream-openssl.c | 5 +++++ src/lib-ssl-iostream/iostream-openssl.h | 1 + 2 files changed, 6 insertions(+) diff --git a/src/lib-ssl-iostream/iostream-openssl.c b/src/lib-ssl-iostream/iostream-openssl.c index 06942bb416..2a42ac5608 100644 --- a/src/lib-ssl-iostream/iostream-openssl.c +++ b/src/lib-ssl-iostream/iostream-openssl.c @@ -345,6 +345,7 @@ static void openssl_iostream_unref(struct ssl_iostream *ssl_io) static void openssl_iostream_destroy(struct ssl_iostream *ssl_io) { + ssl_io->destroyed = TRUE; if (ssl_io->handshaked && SSL_shutdown(ssl_io->ssl) != 1) { /* if bidirectional shutdown fails we need to clear the error queue */ @@ -631,6 +632,10 @@ static int openssl_iostream_handshake(struct ssl_iostream *ssl_io) i_assert(!ssl_io->handshaked); + /* we are being destroyed, so do not do any more handshaking */ + if (ssl_io->destroyed) + return 0; + if (ssl_io->ctx->client_ctx) { while ((ret = SSL_connect(ssl_io->ssl)) <= 0) { ret = openssl_iostream_handle_error(ssl_io, ret, diff --git a/src/lib-ssl-iostream/iostream-openssl.h b/src/lib-ssl-iostream/iostream-openssl.h index 9cefe2d0e9..ca34fae623 100644 --- a/src/lib-ssl-iostream/iostream-openssl.h +++ b/src/lib-ssl-iostream/iostream-openssl.h @@ -66,6 +66,7 @@ struct ssl_iostream { bool want_read:1; bool ostream_flush_waiting_input:1; bool closed:1; + bool destroyed:1; }; extern int dovecot_ssl_extdata_index;