[Python-checkins] cpython (3.5): fix corner cases in the management of server_hostname (closes #27773)

benjamin.peterson python-checkins at python.org
Tue Aug 16 00:56:23 EDT 2016


https://hg.python.org/cpython/rev/98c86d5a6655
changeset:   102686:98c86d5a6655
branch:      3.5
parent:      102684:096e800e6834
user:        Benjamin Peterson <benjamin at python.org>
date:        Mon Aug 15 21:55:37 2016 -0700
summary:
  fix corner cases in the management of server_hostname (closes #27773)

files:
  Misc/NEWS      |   2 ++
  Modules/_ssl.c |  10 ++++------
  2 files changed, 6 insertions(+), 6 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -34,6 +34,8 @@
 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.
 
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -487,7 +487,6 @@
 {
     PySSLSocket *self;
     SSL_CTX *ctx = sslctx->ctx;
-    PyObject *hostname;
     long mode;
 
     self = PyObject_New(PySSLSocket, &PySSLSocket_Type);
@@ -501,16 +500,16 @@
     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 @@
         self->Socket = PyWeakref_NewRef((PyObject *) sock, NULL);
         if (self->Socket == NULL) {
             Py_DECREF(self);
-            Py_XDECREF(self->server_hostname);
             return NULL;
         }
     }

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list