]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
fix corner cases in the management of server_hostname (closes #27773)
authorBenjamin Peterson <benjamin@python.org>
Tue, 16 Aug 2016 04:55:37 +0000 (21:55 -0700)
committerBenjamin Peterson <benjamin@python.org>
Tue, 16 Aug 2016 04:55:37 +0000 (21:55 -0700)
Misc/NEWS
Modules/_ssl.c

index 1de23b575fb0a698235daf1713af4a1929869ad4..4a0d84c9efce91148d41a817c7011e7ce7014b03 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -34,6 +34,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #27773: Correct some memory management errors server_hostname in _ssl.wrap_socket().
+
 - Issue #26750: unittest.mock.create_autospec() now works properly for
   subclasses of property() and other data descriptors.
 
index c21c0f80112f4cb28120ee4dff1f0da711f3b70e..391034ea56c0fd7f0ed3450ddceac5dd2e52bdf3 100644 (file)
@@ -487,7 +487,6 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
 {
     PySSLSocket *self;
     SSL_CTX *ctx = sslctx->ctx;
-    PyObject *hostname;
     long mode;
 
     self = PyObject_New(PySSLSocket, &PySSLSocket_Type);
@@ -501,16 +500,16 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
     self->shutdown_seen_zero = 0;
     self->handshake_done = 0;
     self->owner = NULL;
+    self->server_hostname = NULL;
     if (server_hostname != NULL) {
-        hostname = PyUnicode_Decode(server_hostname, strlen(server_hostname),
-                                   "idna", "strict");
+        PyObject *hostname = PyUnicode_Decode(server_hostname, strlen(server_hostname),
+                                              "idna", "strict");
         if (hostname == NULL) {
             Py_DECREF(self);
             return NULL;
         }
         self->server_hostname = hostname;
-    } else
-        self->server_hostname = NULL;
+    }
 
     Py_INCREF(sslctx);
 
@@ -563,7 +562,6 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
         self->Socket = PyWeakref_NewRef((PyObject *) sock, NULL);
         if (self->Socket == NULL) {
             Py_DECREF(self);
-            Py_XDECREF(self->server_hostname);
             return NULL;
         }
     }