diff options
author | Martin Panter <vadmium+py@gmail.com> | 2016-07-11 01:32:09 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2016-07-11 01:32:09 (GMT) |
commit | 7386268ffd5a87ec03f80773c4cd8bf9dc9953f6 (patch) | |
tree | ddee745e0fe47397df0316a14a22eb19c06c6a44 | |
parent | 4bf9c51f9b37dd08a2c02f637b5854ca6c8b8247 (diff) | |
parent | bed7f1a51245e9c9ca63eeea779f387bfd5a05af (diff) | |
download | cpython-7386268ffd5a87ec03f80773c4cd8bf9dc9953f6.zip cpython-7386268ffd5a87ec03f80773c4cd8bf9dc9953f6.tar.gz cpython-7386268ffd5a87ec03f80773c4cd8bf9dc9953f6.tar.bz2 |
Issue #23804: Merge SSL recv() fix from 3.5
-rw-r--r-- | Lib/test/test_ssl.py | 29 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Modules/_ssl.c | 8 |
3 files changed, 32 insertions, 8 deletions
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py index 7824e9c..6cd5454 100644 --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -2788,20 +2788,13 @@ if _have_threads: # 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 @@ -2817,6 +2810,26 @@ if _have_threads: s.close() + def test_recv_zero(self): + server = ThreadedEchoServer(CERTFILE) + server.__enter__() + self.addCleanup(server.__exit__, None, None) + s = socket.create_connection((HOST, server.port)) + self.addCleanup(s.close) + s = ssl.wrap_socket(s, suppress_ragged_eofs=False) + self.addCleanup(s.close) + + # recv/read(0) should return no data + s.send(b"data") + self.assertEqual(s.recv(0), b"") + self.assertEqual(s.read(0), b"") + self.assertEqual(s.read(), b"data") + + # Should not block if the other end sends no data + s.setblocking(False) + self.assertEqual(s.recv(0), b"") + self.assertEqual(s.recv_into(bytearray()), 0) + def test_nonblocking_send(self): server = ThreadedEchoServer(CERTFILE, certreqs=ssl.CERT_NONE, @@ -27,6 +27,9 @@ Core and Builtins Library ------- +- Issue #23804: Fix SSL zero-length recv() calls to not block and not raise + an error about unclean EOF. + - Issue #27466: Change time format returned by http.cookie.time2netscape, confirming the netscape cookie format and making it consistent with documentation. diff --git a/Modules/_ssl.c b/Modules/_ssl.c index 8c3bb71..0e979e0 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -1913,6 +1913,10 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1, dest = PyBytes_FromStringAndSize(NULL, len); if (dest == NULL) goto error; + if (len == 0) { + Py_XDECREF(sock); + return dest; + } mem = PyBytes_AS_STRING(dest); } else { @@ -1924,6 +1928,10 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1, "maximum length can't fit in a C 'int'"); goto error; } + if (len == 0) { + count = 0; + goto done; + } } } |