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

Skip to content

Commit 86073dc

Browse files
committed
(Merge 3.3) 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.
2 parents 14b9b11 + 6efa965 commit 86073dc

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

Misc/NEWS

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ Core and Builtins
129129
Library
130130
-------
131131

132+
132133
- Issue #11390: Add -o and -f command line options to the doctest CLI to
133134
specify doctest options (and convert it to using argparse).
134135

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

139141
- Issue #11016: Add C implementation of the stat module as _stat.
140142

Modules/_ssl.c

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

1341+
if (buf.len > INT_MAX) {
1342+
PyErr_Format(PyExc_OverflowError,
1343+
"string longer than %d bytes", INT_MAX);
1344+
goto error;
1345+
}
1346+
13411347
/* just in case the blocking state of the socket has been changed */
13421348
nonblocking = (sock->sock_timeout >= 0.0);
13431349
BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking);
@@ -1358,9 +1364,8 @@ static PyObject *PySSL_SSLwrite(PySSLSocket *self, PyObject *args)
13581364
goto error;
13591365
}
13601366
do {
1361-
len = (int)Py_MIN(buf.len, INT_MAX);
13621367
PySSL_BEGIN_ALLOW_THREADS
1363-
len = SSL_write(self->ssl, buf.buf, len);
1368+
len = SSL_write(self->ssl, buf.buf, (int)buf.len);
13641369
err = SSL_get_error(self->ssl, len);
13651370
PySSL_END_ALLOW_THREADS
13661371
if (PyErr_CheckSignals()) {

0 commit comments

Comments
 (0)