cpython: 72c457f9533a (original) (raw)
Mercurial > cpython
changeset 100777:72c457f9533a
Issue #23804: Merge SSL zero read fix from 3.5 [#23804]
Martin Panter vadmium+py@gmail.com | |
---|---|
date | Mon, 28 Mar 2016 01:09:13 +0000 |
parents | a90f5e2b7160(current diff)7a3c5f7dda86(diff) |
children | 9fdeca5fdbf0 |
files | Lib/test/test_ssl.py Misc/NEWS |
diffstat | 4 files changed, 15 insertions(+), 5 deletions(-)[+] [-] Doc/library/ssl.rst 2 Lib/ssl.py 6 Lib/test/test_ssl.py 9 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Doc/library/ssl.rst
+++ b/Doc/library/ssl.rst
@@ -842,7 +842,7 @@ SSL Sockets
SSL sockets also have the following additional methods and attributes:
-.. method:: SSLSocket.read(len=0, buffer=None)
+.. method:: SSLSocket.read(len=1024, buffer=None)
Read up to len bytes of data from the SSL socket and return the result as
a bytes
instance. If buffer is specified, then read into the buffer
--- a/Lib/ssl.py +++ b/Lib/ssl.py @@ -561,7 +561,7 @@ class SSLObject: server hostame is set.""" return self._sslobj.server_hostname
- def read(self, len=1024, buffer=None): """Read up to 'len' bytes from the SSL object and return them.
If 'buffer' is provided, read into this buffer and return the number of @@ -570,7 +570,7 @@ class SSLObject: if buffer is not None: v = self._sslobj.read(len, buffer) else:
v = self._sslobj.read(len or 1024)[](#l2.16)
v = self._sslobj.read(len)[](#l2.17) return v[](#l2.18)
def write(self, data): @@ -776,7 +776,7 @@ class SSLSocket(socket): # EAGAIN. self.getpeername()
- def read(self, len=1024, buffer=None): """Read up to LEN bytes and return them. Return zero-length string on EOF."""
--- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -2783,13 +2783,20 @@ if _have_threads: # consume data s.read()
data = b"data"[](#l3.7)
+ # read(-1, buffer) is supported, even though read(-1) is not
data = b"data"[](#l3.10) s.send(data)[](#l3.11) buffer = bytearray(len(data))[](#l3.12) self.assertEqual(s.read(-1, buffer), len(data))[](#l3.13) self.assertEqual(buffer, data)[](#l3.14)
# recv/read(0) should return no data[](#l3.16)
s.send(data)[](#l3.17)
self.assertEqual(s.recv(0), b"")[](#l3.18)
self.assertEqual(s.read(0), b"")[](#l3.19)
self.assertEqual(s.read(), data)[](#l3.20)
+ # Make sure sendmsg et al are disallowed to avoid # inadvertent disclosure of data and/or corruption # of the encrypted data stream