summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-04-23 23:07:37 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-04-23 23:07:37 (GMT)
commit3df58d11be781c6842d64bb5e8d591659e1f5c0b (patch)
treec1bfbbd0af6756dfec3aaa88d1016889e5415116
parent07072168fb939e594e47d90a4af938cc46eb6217 (diff)
downloadcpython-3df58d11be781c6842d64bb5e8d591659e1f5c0b.zip
cpython-3df58d11be781c6842d64bb5e8d591659e1f5c0b.tar.gz
cpython-3df58d11be781c6842d64bb5e8d591659e1f5c0b.tar.bz2
Merged revisions 80423 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r80423 | antoine.pitrou | 2010-04-24 00:54:59 +0200 (sam., 24 avril 2010) | 4 lines Issue #7943: Fix circular reference created when instantiating an SSL socket. Initial patch by Péter Szabó. ........
-rw-r--r--Lib/ssl.py17
-rw-r--r--Lib/test/test_ssl.py10
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
4 files changed, 23 insertions, 8 deletions
diff --git a/Lib/ssl.py b/Lib/ssl.py
index 58fd2b0..0ebef58 100644
--- a/Lib/ssl.py
+++ b/Lib/ssl.py
@@ -74,7 +74,7 @@ from _ssl import \
SSL_ERROR_EOF, \
SSL_ERROR_INVALID_ERROR_CODE
-from socket import socket, _fileobject
+from socket import socket, _fileobject, _delegate_methods
from socket import getnameinfo as _getnameinfo
import base64 # for DER-to-PEM translation
@@ -90,13 +90,14 @@ class SSLSocket(socket):
do_handshake_on_connect=True,
suppress_ragged_eofs=True):
socket.__init__(self, _sock=sock._sock)
- # the initializer for socket trashes the methods (tsk, tsk), so...
- self.send = lambda data, flags=0: SSLSocket.send(self, data, flags)
- self.sendto = lambda data, addr, flags=0: SSLSocket.sendto(self, data, addr, flags)
- self.recv = lambda buflen=1024, flags=0: SSLSocket.recv(self, buflen, flags)
- self.recvfrom = lambda addr, buflen=1024, flags=0: SSLSocket.recvfrom(self, addr, buflen, flags)
- self.recv_into = lambda buffer, nbytes=None, flags=0: SSLSocket.recv_into(self, buffer, nbytes, flags)
- self.recvfrom_into = lambda buffer, nbytes=None, flags=0: SSLSocket.recvfrom_into(self, buffer, nbytes, flags)
+ # The initializer for socket overrides the methods send(), recv(), etc.
+ # in the instancce, which we don't need -- but we want to provide the
+ # methods defined in SSLSocket.
+ for attr in _delegate_methods:
+ try:
+ delattr(self, attr)
+ except AttributeError:
+ pass
if certfile and not keyfile:
keyfile = certfile
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index 12373d1..ef82ed3 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -14,6 +14,7 @@ import pprint
import urllib, urlparse
import shutil
import traceback
+import weakref
from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
@@ -113,6 +114,15 @@ class BasicTests(unittest.TestCase):
if (d1 != d2):
raise test_support.TestFailed("PEM-to-DER or DER-to-PEM translation failed")
+ def test_refcycle(self):
+ # Issue #7943: an SSL object doesn't create reference cycles with
+ # itself.
+ s = socket.socket(socket.AF_INET)
+ ss = ssl.wrap_socket(s)
+ wr = weakref.ref(ss)
+ del ss
+ self.assertEqual(wr(), None)
+
class NetworkedTests(unittest.TestCase):
def testConnect(self):
diff --git a/Misc/ACKS b/Misc/ACKS
index 1caa20f..84292b1 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -701,6 +701,7 @@ Andrew Svetlov
Kalle Svensson
Paul Swartz
Thenault Sylvain
+Péter Szabó
Arfrever Frehtes Taifersar Arahesis
Geoff Talvola
William Tanksley
diff --git a/Misc/NEWS b/Misc/NEWS
index 625221a..2911096 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -33,6 +33,9 @@ Core and Builtins
Library
-------
+- Issue #7943: Fix circular reference created when instantiating an SSL
+ socket. Initial patch by Péter Szabó.
+
- Issue #8108: Fix the unwrap() method of SSL objects when the socket has
a non-infinite timeout. Also make that method friendlier with applications
wanting to continue using the socket in clear-text mode, by disabling