Skip to content

Commit 806b7c2

Browse files
trengginassauwming
authored andcommitted
Don't call SSL_shutdown() when receiving SSL_ERROR_SYSCALL or SSL_ERROR_SSL (#3577)
1 parent bbf7f22 commit 806b7c2

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

pjlib/src/pj/ssl_sock_imp_common.c

+1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ static void ssl_close_sockets(pj_ssl_sock_t *ssock)
244244
static pj_bool_t on_handshake_complete(pj_ssl_sock_t *ssock,
245245
pj_status_t status)
246246
{
247+
ssock->handshake_status = status;
247248
/* Cancel handshake timer */
248249
if (ssock->timer.id == TIMER_HANDSHAKE_TIMEOUT) {
249250
pj_timer_heap_cancel(ssock->param.timer_heap, &ssock->timer);

pjlib/src/pj/ssl_sock_imp_common.h

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ struct pj_ssl_sock_t
112112
pj_ioqueue_op_key_t shutdown_op_key;
113113
pj_timer_entry timer;
114114
pj_status_t verify_status;
115+
pj_status_t handshake_status;
115116

116117
pj_bool_t is_closing;
117118
unsigned long last_err;

pjlib/src/pj/ssl_sock_ossl.c

+12-5
Original file line numberDiff line numberDiff line change
@@ -1714,13 +1714,20 @@ static void ssl_reset_sock_state(pj_ssl_sock_t *ssock)
17141714
* Avoid calling SSL_shutdown() if handshake wasn't completed.
17151715
* OpenSSL 1.0.2f complains if SSL_shutdown() is called during an
17161716
* SSL handshake, while previous versions always return 0.
1717+
* Call SSL_shutdown() when there is a timeout handshake failure or
1718+
* the last error is not SSL_ERROR_SYSCALL and not SSL_ERROR_SSL.
17171719
*/
17181720
if (ossock->ossl_ssl && SSL_in_init(ossock->ossl_ssl) == 0) {
1719-
int ret = SSL_shutdown(ossock->ossl_ssl);
1720-
if (ret == 0) {
1721-
/* SSL_shutdown will potentially trigger a bunch of
1722-
* data to dump to the socket */
1723-
post_unlock_flush_circ_buf = 1;
1721+
if (ssock->handshake_status == PJ_ETIMEDOUT ||
1722+
(ssock->last_err != SSL_ERROR_SYSCALL &&
1723+
ssock->last_err != SSL_ERROR_SSL))
1724+
{
1725+
int ret = SSL_shutdown(ossock->ossl_ssl);
1726+
if (ret == 0) {
1727+
/* SSL_shutdown will potentially trigger a bunch of
1728+
* data to dump to the socket */
1729+
post_unlock_flush_circ_buf = 1;
1730+
}
17241731
}
17251732
}
17261733

0 commit comments

Comments
 (0)