Skip to content

Commit 854f7ba

Browse files
njsmithserhiy-storchaka
authored andcommitted
[3.6] bpo-30594: Fixed refcounting in newPySSLSocket (GH-1992) (#1994)
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. (cherry picked from commit 65ece7c)
1 parent 2c7f927 commit 854f7ba

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
@@ -599,6 +599,7 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
599599
self->ssl = NULL;
600600
self->Socket = NULL;
601601
self->ctx = sslctx;
602+
Py_INCREF(sslctx);
602603
self->shutdown_seen_zero = 0;
603604
self->handshake_done = 0;
604605
self->owner = NULL;
@@ -613,8 +614,6 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
613614
self->server_hostname = hostname;
614615
}
615616

616-
Py_INCREF(sslctx);
617-
618617
/* Make sure the SSL error state is initialized */
619618
(void) ERR_get_state();
620619
ERR_clear_error();

0 commit comments

Comments
 (0)