Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6efa965

Browse files
committed
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.
1 parent 51cee7d commit 6efa965

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

Misc/NEWS

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ Core and Builtins
3838
Library
3939
-------
4040

41-
- Issue #18135: Fix a possible integer overflow in ssl.SSLSocket.write()
42-
and in ssl.SSLContext.load_cert_chain() for strings and passwords longer than
43-
2 gigabytes.
41+
- Issue #18135: ssl.SSLSocket.write() now raises an OverflowError if the input
42+
string in longer than 2 gigabytes, and ssl.SSLContext.load_cert_chain()
43+
raises a ValueError if the password is longer than 2 gigabytes. The ssl
44+
module does not support partial write.
4445

4546
- Issue #18248: Fix libffi build on AIX.
4647

Modules/_ssl.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,12 @@ static PyObject *PySSL_SSLwrite(PySSLSocket *self, PyObject *args)
12641264
return NULL;
12651265
}
12661266

1267+
if (buf.len > INT_MAX) {
1268+
PyErr_Format(PyExc_OverflowError,
1269+
"string longer than %d bytes", INT_MAX);
1270+
goto error;
1271+
}
1272+
12671273
/* just in case the blocking state of the socket has been changed */
12681274
nonblocking = (sock->sock_timeout >= 0.0);
12691275
BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking);
@@ -1284,9 +1290,8 @@ static PyObject *PySSL_SSLwrite(PySSLSocket *self, PyObject *args)
12841290
goto error;
12851291
}
12861292
do {
1287-
len = (int)Py_MIN(buf.len, INT_MAX);
12881293
PySSL_BEGIN_ALLOW_THREADS
1289-
len = SSL_write(self->ssl, buf.buf, len);
1294+
len = SSL_write(self->ssl, buf.buf, (int)buf.len);
12901295
err = SSL_get_error(self->ssl, len);
12911296
PySSL_END_ALLOW_THREADS
12921297
if (PyErr_CheckSignals()) {

0 commit comments

Comments
 (0)