File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5307,17 +5307,20 @@ _ssl__SSLContext_sni_callback_set_impl(PySSLContext *self, PyObject *value)
53075307 "sni_callback cannot be set on TLS_CLIENT context" );
53085308 return -1 ;
53095309 }
5310- SSL_CTX_set_tlsext_servername_callback (self -> ctx , NULL );
5311- Py_CLEAR (self -> set_sni_cb );
5312- if (value != Py_None ) {
5313- if (!PyCallable_Check (value )) {
5314- PyErr_SetString (PyExc_TypeError ,
5315- "not a callable object" );
5310+ if (!PyCallable_Check (value )) {
5311+ SSL_CTX_set_tlsext_servername_callback (self -> ctx , NULL );
5312+ Py_CLEAR (self -> set_sni_cb );
5313+ if (value != Py_None ) {
5314+ PyErr_SetString (PyExc_TypeError , "not a callable object" );
53165315 return -1 ;
53175316 }
5318- self -> set_sni_cb = Py_NewRef (value );
5319- SSL_CTX_set_tlsext_servername_callback (self -> ctx , _servername_callback );
5317+ }
5318+ else {
5319+ Py_INCREF (value );
5320+ PyObject * old_cb = _Py_atomic_exchange_ptr (& self -> set_sni_cb , value );
5321+ Py_XDECREF (old_cb );
53205322 SSL_CTX_set_tlsext_servername_arg (self -> ctx , self );
5323+ SSL_CTX_set_tlsext_servername_callback (self -> ctx , _servername_callback );
53215324 }
53225325 return 0 ;
53235326}
You can’t perform that action at this time.
0 commit comments