Skip to content

Commit 83d1430

Browse files
authored
bpo-42854: Correctly use size_t for _ssl._SSLSocket.read and _ssl._SSLSocket.write (GH-27271)
1 parent 8f42106 commit 83d1430

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed a bug in the :mod:`_ssl` module that was throwing :exc:`OverflowError`
2+
when using :meth:`_ssl._SSLSocket.write` and :meth:`_ssl._SSLSocket.read`
3+
for a big value of the ``len`` parameter. Patch by Pablo Galindo

Modules/_ssl.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,7 +2346,7 @@ _ssl__SSLSocket_write_impl(PySSLSocket *self, Py_buffer *b)
23462346

23472347
do {
23482348
PySSL_BEGIN_ALLOW_THREADS
2349-
retval = SSL_write_ex(self->ssl, b->buf, (int)b->len, &count);
2349+
retval = SSL_write_ex(self->ssl, b->buf, (size_t)b->len, &count);
23502350
err = _PySSL_errno(retval == 0, self->ssl, retval);
23512351
PySSL_END_ALLOW_THREADS
23522352
self->err = err;
@@ -2418,7 +2418,7 @@ _ssl__SSLSocket_pending_impl(PySSLSocket *self)
24182418

24192419
/*[clinic input]
24202420
_ssl._SSLSocket.read
2421-
size as len: int
2421+
size as len: Py_ssize_t
24222422
[
24232423
buffer: Py_buffer(accept={rwbuffer})
24242424
]
@@ -2428,9 +2428,9 @@ Read up to size bytes from the SSL socket.
24282428
[clinic start generated code]*/
24292429

24302430
static PyObject *
2431-
_ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1,
2432-
Py_buffer *buffer)
2433-
/*[clinic end generated code: output=00097776cec2a0af input=ff157eb918d0905b]*/
2431+
_ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len,
2432+
int group_right_1, Py_buffer *buffer)
2433+
/*[clinic end generated code: output=49b16e6406023734 input=ec48bf622be1c4a1]*/
24342434
{
24352435
PyObject *dest = NULL;
24362436
char *mem;
@@ -2498,7 +2498,7 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1,
24982498

24992499
do {
25002500
PySSL_BEGIN_ALLOW_THREADS
2501-
retval = SSL_read_ex(self->ssl, mem, len, &count);
2501+
retval = SSL_read_ex(self->ssl, mem, (size_t)len, &count);
25022502
err = _PySSL_errno(retval == 0, self->ssl, retval);
25032503
PySSL_END_ALLOW_THREADS
25042504
self->err = err;

Modules/clinic/_ssl.c.h

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)