diff options
author | Martin Panter <vadmium+py@gmail.com> | 2016-03-27 10:40:22 +0000 |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2016-03-27 10:40:22 +0000 |
commit | afd465d49707618f40d3c64fa499a38f9c9db3d2 (patch) | |
tree | 6e6efd88fc22bdb81236f159c95cb7c72c99b1ca | |
parent | 3625af5f2129f8e8735c54bd01d9f138dd5c0e83 (diff) | |
parent | 5503d4731e822e90eea387efa37934d2df41c784 (diff) | |
download | cpython-git-afd465d49707618f40d3c64fa499a38f9c9db3d2.tar.gz |
Issue #26644: Merge SSL negative read fix from 3.5
-rw-r--r-- | Lib/test/test_ssl.py | 11 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Modules/_ssl.c | 5 |
3 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py index 8b72ca9b8a..f86bbc1bf8 100644 --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -2783,6 +2783,13 @@ if _have_threads: # consume data s.read() + # 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) + # Make sure sendmsg et al are disallowed to avoid # inadvertent disclosure of data and/or corruption # of the encrypted data stream @@ -2792,6 +2799,10 @@ if _have_threads: s.recvmsg_into, bytearray(100)) s.write(b"over\n") + + self.assertRaises(ValueError, s.recv, -1) + self.assertRaises(ValueError, s.read, -1) + s.close() def test_nonblocking_send(self): @@ -232,6 +232,9 @@ Core and Builtins Library ------- +- Issue #26644: Raise ValueError rather than SystemError when a negative + length is passed to SSLSocket.recv() or read(). + - Issue #26616: Fixed a bug in datetime.astimezone() method. - Issue #26637: The :mod:`importlib` module now emits an :exc:`ImportError` diff --git a/Modules/_ssl.c b/Modules/_ssl.c index c96237ed9d..838d5ba6f4 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -1895,6 +1895,11 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1, _PyTime_t timeout, deadline = 0; int has_timeout; + if (!group_right_1 && len < 0) { + PyErr_SetString(PyExc_ValueError, "size should not be negative"); + return NULL; + } + if (sock != NULL) { if (((PyObject*)sock) == Py_None) { _setSSLError("Underlying socket connection gone", |