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
65ece7ca2366308fa91a39a8dfa255e6bdce3cca)
self->ssl = NULL;
self->Socket = NULL;
self->ctx = sslctx;
+ Py_INCREF(sslctx);
self->shutdown_seen_zero = 0;
self->handshake_done = 0;
self->owner = NULL;
self->server_hostname = hostname;
}
- Py_INCREF(sslctx);
-
/* Make sure the SSL error state is initialized */
(void) ERR_get_state();
ERR_clear_error();