summaryrefslogtreecommitdiffstats
path: root/Modules/_ssl.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-04-11 18:48:42 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-04-11 18:48:42 (GMT)
commit50b24d0d7cc7b787acc1f8481173e5e0d536fe28 (patch)
tree7465cab4d1a418ce907c6d60aafd3ba9376aa529 /Modules/_ssl.c
parent85b2afb1b1f3e24b1ecddfc955b5d4614fc6f39e (diff)
downloadcpython-50b24d0d7cc7b787acc1f8481173e5e0d536fe28.zip
cpython-50b24d0d7cc7b787acc1f8481173e5e0d536fe28.tar.gz
cpython-50b24d0d7cc7b787acc1f8481173e5e0d536fe28.tar.bz2
Fix a crash when setting a servername callback on a SSL server socket and the client doesn't send a server name.
Patch by Kazuhiro Yoshida. (originally issue #8109)
Diffstat (limited to 'Modules/_ssl.c')
-rw-r--r--Modules/_ssl.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 971dd05..c6493ba 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -2448,22 +2448,28 @@ _servername_callback(SSL *s, int *al, void *args)
goto error;
}
- servername_o = PyBytes_FromString(servername);
- if (servername_o == NULL) {
- PyErr_WriteUnraisable((PyObject *) ssl_ctx);
- goto error;
+ if (servername == NULL) {
+ result = PyObject_CallFunctionObjArgs(ssl_ctx->set_hostname, ssl_socket,
+ Py_None, ssl_ctx, NULL);
}
- servername_idna = PyUnicode_FromEncodedObject(servername_o, "idna", NULL);
- if (servername_idna == NULL) {
- PyErr_WriteUnraisable(servername_o);
+ else {
+ servername_o = PyBytes_FromString(servername);
+ if (servername_o == NULL) {
+ PyErr_WriteUnraisable((PyObject *) ssl_ctx);
+ goto error;
+ }
+ servername_idna = PyUnicode_FromEncodedObject(servername_o, "idna", NULL);
+ if (servername_idna == NULL) {
+ PyErr_WriteUnraisable(servername_o);
+ Py_DECREF(servername_o);
+ goto error;
+ }
Py_DECREF(servername_o);
- goto error;
+ result = PyObject_CallFunctionObjArgs(ssl_ctx->set_hostname, ssl_socket,
+ servername_idna, ssl_ctx, NULL);
+ Py_DECREF(servername_idna);
}
- Py_DECREF(servername_o);
- result = PyObject_CallFunctionObjArgs(ssl_ctx->set_hostname, ssl_socket,
- servername_idna, ssl_ctx, NULL);
Py_DECREF(ssl_socket);
- Py_DECREF(servername_idna);
if (result == NULL) {
PyErr_WriteUnraisable(ssl_ctx->set_hostname);