Skip to content

Commit 65ece7c

Browse files
njsmithserhiy-storchaka
authored andcommitted
bpo-30594: Fixed refcounting in newPySSLSocket (#1992)
If pass a server_hostname= that fails IDNA decoding to SSLContext.wrap_socket or SSLContext.wrap_bio, then the SSLContext object had a spurious Py_DECREF called on it, eventually leading to segfaults.
1 parent 0ecdc52 commit 65ece7c

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

Modules/_ssl.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
596596
self->ssl = NULL;
597597
self->Socket = NULL;
598598
self->ctx = sslctx;
599+
Py_INCREF(sslctx);
599600
self->shutdown_seen_zero = 0;
600601
self->owner = NULL;
601602
self->server_hostname = NULL;
@@ -609,8 +610,6 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
609610
self->server_hostname = hostname;
610611
}
611612

612-
Py_INCREF(sslctx);
613-
614613
/* Make sure the SSL error state is initialized */
615614
(void) ERR_get_state();
616615
ERR_clear_error();

0 commit comments

Comments
 (0)