summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-07-09 03:15:36 -0700
committerGitHub <noreply@github.com>2020-07-09 03:15:36 -0700
commit54babbe976531d4d1c21ea415f71e7c6846e15bc (patch)
tree16a07905bfb6b788a558ac3cd1b19d4ba2e999fc
parentc1c50345933efca42169f03d79ff4fe3d9c06bdc (diff)
downloadcpython-git-54babbe976531d4d1c21ea415f71e7c6846e15bc.tar.gz
bpo-41252: Fix incorrect refcounting in _ssl.c's _servername_callback() (GH-21407)
(cherry picked from commit ee96f32ca24779656d3c8736d26671fc3689f0a3) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2020-07-08-21-55-23.bpo-41252.nBWL-Y.rst1
-rw-r--r--Modules/_ssl.c3
2 files changed, 3 insertions, 1 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-07-08-21-55-23.bpo-41252.nBWL-Y.rst b/Misc/NEWS.d/next/Core and Builtins/2020-07-08-21-55-23.bpo-41252.nBWL-Y.rst
new file mode 100644
index 0000000000..65f3189c83
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2020-07-08-21-55-23.bpo-41252.nBWL-Y.rst
@@ -0,0 +1 @@
+Fix incorrect refcounting in _ssl.c's ``_servername_callback()``.
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 8ee2c17036..1944393e54 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -4548,11 +4548,12 @@ _servername_callback(SSL *s, int *al, void *args)
* back into a str object, but still as an A-label (bpo-28414)
*/
servername_str = PyUnicode_FromEncodedObject(servername_bytes, "ascii", NULL);
- Py_DECREF(servername_bytes);
if (servername_str == NULL) {
PyErr_WriteUnraisable(servername_bytes);
+ Py_DECREF(servername_bytes);
goto error;
}
+ Py_DECREF(servername_bytes);
result = PyObject_CallFunctionObjArgs(
ssl_ctx->set_sni_cb, ssl_socket, servername_str,
ssl_ctx, NULL);