[Python-checkins] cpython (merge 3.5 -> default): Issue #23804: Merge SSL zero read fix from 3.5
martin.panter
python-checkins at python.org
Sun Mar 27 23:08:39 EDT 2016
https://hg.python.org/cpython/rev/72c457f9533a
changeset: 100777:72c457f9533a
parent: 100775:a90f5e2b7160
parent: 100776:7a3c5f7dda86
user: Martin Panter <vadmium+py at gmail.com>
date: Mon Mar 28 01:09:13 2016 +0000
summary:
Issue #23804: Merge SSL zero read fix from 3.5
files:
Doc/library/ssl.rst | 2 +-
Lib/ssl.py | 6 +++---
Lib/test/test_ssl.py | 9 ++++++++-
Misc/NEWS | 3 +++
4 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/Doc/library/ssl.rst b/Doc/library/ssl.rst
--- a/Doc/library/ssl.rst
+++ b/Doc/library/ssl.rst
@@ -842,7 +842,7 @@
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
diff --git a/Lib/ssl.py b/Lib/ssl.py
--- a/Lib/ssl.py
+++ b/Lib/ssl.py
@@ -561,7 +561,7 @@
server hostame is set."""
return self._sslobj.server_hostname
- def read(self, len=0, buffer=None):
+ 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 @@
if buffer is not None:
v = self._sslobj.read(len, buffer)
else:
- v = self._sslobj.read(len or 1024)
+ v = self._sslobj.read(len)
return v
def write(self, data):
@@ -776,7 +776,7 @@
# EAGAIN.
self.getpeername()
- def read(self, len=0, buffer=None):
+ def read(self, len=1024, buffer=None):
"""Read up to LEN bytes and return them.
Return zero-length string on EOF."""
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -2783,13 +2783,20 @@
# consume data
s.read()
+ data = b"data"
+
# read(-1, buffer) is supported, even though read(-1) is not
- data = b"data"
s.send(data)
buffer = bytearray(len(data))
self.assertEqual(s.read(-1, buffer), len(data))
self.assertEqual(buffer, data)
+ # recv/read(0) should return no data
+ s.send(data)
+ self.assertEqual(s.recv(0), b"")
+ self.assertEqual(s.read(0), b"")
+ self.assertEqual(s.read(), data)
+
# Make sure sendmsg et al are disallowed to avoid
# inadvertent disclosure of data and/or corruption
# of the encrypted data stream
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -239,6 +239,9 @@
- Issue #26644: Raise ValueError rather than SystemError when a negative
length is passed to SSLSocket.recv() or read().
+- Issue #23804: Fix SSL recv(0) and read(0) methods to return zero bytes
+ instead of up to 1024.
+
- Issue #26616: Fixed a bug in datetime.astimezone() method.
- Issue #26637: The :mod:`importlib` module now emits an :exc:`ImportError`
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list