]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #18135: ssl.SSLSocket.write() now raises an OverflowError if the input
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 24 Jun 2013 22:42:31 +0000 (00:42 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 24 Jun 2013 22:42:31 +0000 (00:42 +0200)
string in longer than 2 gigabytes, and ssl.SSLContext.load_cert_chain() raises
a ValueError if the password is longer than 2 gigabytes. The ssl module does
not support partial write.

Misc/NEWS
Modules/_ssl.c

index f5a35bc8194315fa414972ed3069e9220ad51540..7e6577310e17cfd1a668ea03c5e48b349892af0c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -38,9 +38,10 @@ Core and Builtins
 Library
 -------
 
-- Issue #18135: Fix a possible integer overflow in ssl.SSLSocket.write()
-  and in ssl.SSLContext.load_cert_chain() for strings and passwords longer than
-  2 gigabytes.
+- Issue #18135: ssl.SSLSocket.write() now raises an OverflowError if the input
+  string in longer than 2 gigabytes, and ssl.SSLContext.load_cert_chain()
+  raises a ValueError if the password is longer than 2 gigabytes. The ssl
+  module does not support partial write.
 
 - Issue #18248: Fix libffi build on AIX.
 
index ebd84d51e12ff315fbad87d5604c189fe5bb352b..434729fa9ab1d9bd72bbfe62490eb2ee8bd5be3d 100644 (file)
@@ -1264,6 +1264,12 @@ static PyObject *PySSL_SSLwrite(PySSLSocket *self, PyObject *args)
         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 = (sock->sock_timeout >= 0.0);
     BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking);
@@ -1284,9 +1290,8 @@ static PyObject *PySSL_SSLwrite(PySSLSocket *self, PyObject *args)
         goto error;
     }
     do {
-        len = (int)Py_MIN(buf.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()) {