Skip to content

Commit

Permalink
[3.5] bpo-30594: Fixed refcounting in newPySSLSocket (GH-1992) (#1993)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
njsmith authored and serhiy-storchaka committed Jun 8, 2017
1 parent e3a0ce2 commit 54ba41e
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
self->ssl = NULL;
self->Socket = NULL;
self->ctx = sslctx;
Py_INCREF(sslctx);
self->shutdown_seen_zero = 0;
self->handshake_done = 0;
self->owner = NULL;
Expand All @@ -584,8 +585,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();
Expand Down

0 comments on commit 54ba41e

Please sign in to comment.