]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41252: Fix incorrect refcounting in _ssl.c's _servername_callback() (GH-21407)
authorZackery Spytz <zspytz@gmail.com>
Thu, 9 Jul 2020 10:00:21 +0000 (04:00 -0600)
committerGitHub <noreply@github.com>
Thu, 9 Jul 2020 10:00:21 +0000 (03:00 -0700)
Misc/NEWS.d/next/Core and Builtins/2020-07-08-21-55-23.bpo-41252.nBWL-Y.rst [new file with mode: 0644]
Modules/_ssl.c

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 (file)
index 0000000..65f3189
--- /dev/null
@@ -0,0 +1 @@
+Fix incorrect refcounting in _ssl.c's ``_servername_callback()``.
index 58064178a1a343d0de20c3c1519c7ceb8483ed3b..a8c339d9f33344cf33f8b6386475ef9c4257d159 100644 (file)
@@ -4545,11 +4545,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);