]> granicus.if.org Git - python/commitdiff
Issue #23804: Fix SSL recv/read(0) to not return 1024 bytes
authorMartin Panter <vadmium+py@gmail.com>
Mon, 28 Mar 2016 00:22:09 +0000 (00:22 +0000)
committerMartin Panter <vadmium+py@gmail.com>
Mon, 28 Mar 2016 00:22:09 +0000 (00:22 +0000)
Doc/library/ssl.rst
Lib/ssl.py
Lib/test/test_ssl.py
Misc/NEWS

index 79b1a4783f0fb4370a607d644dc670004d31948b..98e866fe8c573359faa9c34158fd3d68b42ffd90 100644 (file)
@@ -842,7 +842,7 @@ SSL Sockets
 
 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
index df39592327932f35839d6fb36f197c19268ef52e..65ad38f899ed4660fe21c20dc9ce6091803e5301 100644 (file)
@@ -561,7 +561,7 @@ class SSLObject:
         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 @@ class SSLObject:
         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 @@ class SSLSocket(socket):
             # 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."""
 
index 8c0dd31c326f29c6ac2a3452f181e293cc3f424b..645ec8d100c41965ffe1d9de6f6d9043fa60628a 100644 (file)
@@ -2792,13 +2792,20 @@ else:
                         # consume data
                         s.read()
 
-                # read(-1, buffer) is supported, even though read(-1) is not
                 data = b"data"
+
+                # read(-1, buffer) is supported, even though read(-1) is not
                 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
index a855451461a5bd277dc02baab463ba9a8c75a1b2..59c0828d5fe53cb62080260091657e65c0031010 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -101,6 +101,9 @@ Library
 - 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 #21925: :func:`warnings.formatwarning` now catches exceptions on