From: Nathaniel J. Smith Date: Thu, 8 Jun 2017 06:30:43 +0000 (-0700) Subject: bpo-30594: Fixed refcounting in newPySSLSocket (#1992) X-Git-Tag: v3.7.0a1~670 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=65ece7ca2366308fa91a39a8dfa255e6bdce3cca;p=thirdparty%2FPython%2Fcpython.git 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. --- diff --git a/Modules/_ssl.c b/Modules/_ssl.c index 147703c11e35..d318b252e830 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -596,6 +596,7 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock, self->ssl = NULL; self->Socket = NULL; self->ctx = sslctx; + Py_INCREF(sslctx); self->shutdown_seen_zero = 0; self->owner = NULL; self->server_hostname = NULL; @@ -609,8 +610,6 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock, self->server_hostname = hostname; } - Py_INCREF(sslctx); - /* Make sure the SSL error state is initialized */ (void) ERR_get_state(); ERR_clear_error();