From 98015a8d0bc15673c3f3e4905725b68468d41765 Mon Sep 17 00:00:00 2001 From: Riza Sulistyo Date: Thu, 14 Sep 2017 05:03:45 +0000 Subject: [PATCH] Re #1994(misc): Avoid calling SSL_shutdown() if handshake wasn't completed otherwise OpenSSL 1.0.2f and newer version will complain. Thanks to Peter Koletzki for the report. git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@5648 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/src/pj/ssl_sock_ossl.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pjlib/src/pj/ssl_sock_ossl.c b/pjlib/src/pj/ssl_sock_ossl.c index b782b7254..e0b079dd4 100644 --- a/pjlib/src/pj/ssl_sock_ossl.c +++ b/pjlib/src/pj/ssl_sock_ossl.c @@ -1070,7 +1070,14 @@ static void destroy_ssl(pj_ssl_sock_t *ssock) { /* Destroy SSL instance */ if (ssock->ossl_ssl) { - SSL_shutdown(ssock->ossl_ssl); + /** + * Avoid calling SSL_shutdown() if handshake wasn't completed. + * OpenSSL 1.0.2f complains if SSL_shutdown() is called during an + * SSL handshake, while previous versions always return 0. + */ + if (SSL_in_init(ssock->ossl_ssl) == 0) { + SSL_shutdown(ssock->ossl_ssl); + } SSL_free(ssock->ossl_ssl); /* this will also close BIOs */ ssock->ossl_ssl = NULL; }