cpython (2.7): Issue #23804: Fix SSL recv/read(0) to not return 1024 bytes
![](https://secure.gravatar.com/avatar/8ac615df352a970211b0e3d94a307c6d.jpg?s=120&d=mm&r=g)
https://hg.python.org/cpython/rev/f4cff2bf9903 changeset: 100778:f4cff2bf9903 branch: 2.7 parent: 100764:b84d136e0028 user: Martin Panter <vadmium+py@gmail.com> date: Mon Mar 28 00:22:09 2016 +0000 summary: Issue #23804: Fix SSL recv/read(0) to not return 1024 bytes files: Lib/ssl.py | 4 ++-- Lib/test/test_ssl.py | 9 ++++++++- Misc/NEWS | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Lib/ssl.py b/Lib/ssl.py --- a/Lib/ssl.py +++ b/Lib/ssl.py @@ -625,7 +625,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.""" @@ -636,7 +636,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 except SSLError as x: if x.args[0] == SSL_ERROR_EOF and self.suppress_ragged_eofs: 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 @@ -2622,13 +2622,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) + s.write(b"over\n") self.assertRaises(ValueError, s.recv, -1) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -64,6 +64,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 #24266: Ctrl+C during Readline history search now cancels the search mode when compiled with Readline 7. -- Repository URL: https://hg.python.org/cpython
participants (1)
-
martin.panter