[Python-checkins] cpython (2.7): Issue #18135: ssl.SSLSocket.write() now raises an OverflowError if the input

victor.stinner python-checkins at python.org
Tue Jun 25 00:48:29 CEST 2013


http://hg.python.org/cpython/rev/a29eaffa7d72
changeset:   84335:a29eaffa7d72
branch:      2.7
parent:      84322:e18b92bae4d6
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Jun 25 00:48:02 2013 +0200
summary:
  Issue #18135: ssl.SSLSocket.write() now raises an OverflowError if the input
string in longer than 2 gigabytes. The ssl module does not support partial
write.

files:
  Misc/NEWS      |   5 +++--
  Modules/_ssl.c |  13 +++++++------
  2 files changed, 10 insertions(+), 8 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -24,8 +24,9 @@
 Library
 -------
 
-- Issue #18135: Fix a possible integer overflow in ssl.SSLSocket.write()
-  for strings longer than 2 gigabytes.
+- Issue #18135: ssl.SSLSocket.write() now raises an OverflowError if the input
+  string in longer than 2 gigabytes. The ssl module does not support partial
+  write.
 
 - Issue #18167: cgi.FieldStorage no more fails to handle multipart/form-data
   when \r\n appears at end of 65535 bytes without other newlines.
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -1192,6 +1192,12 @@
     if (!PyArg_ParseTuple(args, "s*:write", &buf))
         return NULL;
 
+    if (buf.len > INT_MAX) {
+        PyErr_Format(PyExc_OverflowError,
+                     "string longer than %d bytes", INT_MAX);
+        goto error;
+    }
+
     /* just in case the blocking state of the socket has been changed */
     nonblocking = (self->Socket->sock_timeout >= 0.0);
     BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking);
@@ -1212,13 +1218,8 @@
         goto error;
     }
     do {
-        if (buf.len <= INT_MAX)
-            len = (int)buf.len;
-        else
-            len = INT_MAX;
-
         PySSL_BEGIN_ALLOW_THREADS
-        len = SSL_write(self->ssl, buf.buf, len);
+        len = SSL_write(self->ssl, buf.buf, (int)buf.len);
         err = SSL_get_error(self->ssl, len);
         PySSL_END_ALLOW_THREADS
         if (PyErr_CheckSignals()) {

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


More information about the Python-checkins mailing list