Skip to content

Commit

Permalink
openssl: Clear error queue after an incomplete SSL_shutdown
Browse files Browse the repository at this point in the history
If the SSL_shutdown-call fails (e.g. because the underlaying socket has
already been closed) OpenSSL puts the corresponding error into the
queue. We don't care about details so we need to clear the queue.

Otherwise the error will be pulled while error checking the next OpenSSL
call of an unrelated connection.
  • Loading branch information
manuelm authored and sirainen committed Dec 13, 2016
1 parent 3f4d68e commit c927f01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/lib-ssl-iostream/iostream-openssl.c
Expand Up @@ -299,7 +299,11 @@ static void openssl_iostream_unref(struct ssl_iostream *ssl_io)

static void openssl_iostream_destroy(struct ssl_iostream *ssl_io)
{
(void)SSL_shutdown(ssl_io->ssl);
if (SSL_shutdown(ssl_io->ssl) != 1) {
/* if bidirectional shutdown fails we need to clear
the error queue */
openssl_iostream_clear_errors();
}
(void)openssl_iostream_more(ssl_io);
(void)o_stream_flush(ssl_io->plain_output);
/* close the plain i/o streams, because their fd may be closed soon,
Expand Down
6 changes: 5 additions & 1 deletion src/login-common/ssl-proxy-openssl.c
Expand Up @@ -813,7 +813,11 @@ void ssl_proxy_destroy(struct ssl_proxy *proxy)
if (proxy->io_plain_write != NULL)
io_remove(&proxy->io_plain_write);

(void)SSL_shutdown(proxy->ssl);
if (SSL_shutdown(proxy->ssl) != 1) {
/* if bidirectional shutdown fails we need to clear
the error queue. */
openssl_iostream_clear_errors();
}

net_disconnect(proxy->fd_ssl);
net_disconnect(proxy->fd_plain);
Expand Down

0 comments on commit c927f01

Please sign in to comment.