[Python-checkins] cpython (merge 3.5 -> default): Issue #26644: Merge SSL negative read fix from 3.5

martin.panter python-checkins at python.org
Sun Mar 27 06:41:32 EDT 2016


https://hg.python.org/cpython/rev/80934ad2356d
changeset:   100765:80934ad2356d
parent:      100762:9d20901c74f3
parent:      100763:af92651c22e9
user:        Martin Panter <vadmium+py at gmail.com>
date:        Sun Mar 27 10:40:22 2016 +0000
summary:
  Issue #26644: Merge SSL negative read fix from 3.5

files:
  Lib/test/test_ssl.py |  11 +++++++++++
  Misc/NEWS            |   3 +++
  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
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -2783,6 +2783,13 @@
                         # 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 @@
                                   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):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -232,6 +232,9 @@
 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
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -1895,6 +1895,11 @@
     _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",

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list