[Python-checkins] bpo-42854: Correctly use size_t for _ssl._SSLSocket.read and _ssl._SSLSocket.write (GH-27271)
pablogsal
webhook-mailer at python.org
Fri Jul 23 11:06:02 EDT 2021
https://github.com/python/cpython/commit/83d1430ee5b8008631e7f2a75447e740eed065c1
commit: 83d1430ee5b8008631e7f2a75447e740eed065c1
branch: main
author: Pablo Galindo Salgado <Pablogsal at gmail.com>
committer: pablogsal <Pablogsal at gmail.com>
date: 2021-07-23T16:05:53+01:00
summary:
bpo-42854: Correctly use size_t for _ssl._SSLSocket.read and _ssl._SSLSocket.write (GH-27271)
files:
A Misc/NEWS.d/next/Library/2021-07-20-21-51-35.bpo-42854.ThuDMI.rst
M Modules/_ssl.c
M Modules/clinic/_ssl.c.h
diff --git a/Misc/NEWS.d/next/Library/2021-07-20-21-51-35.bpo-42854.ThuDMI.rst b/Misc/NEWS.d/next/Library/2021-07-20-21-51-35.bpo-42854.ThuDMI.rst
new file mode 100644
index 0000000000000..33cbb63a5e14b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-07-20-21-51-35.bpo-42854.ThuDMI.rst
@@ -0,0 +1,3 @@
+Fixed a bug in the :mod:`_ssl` module that was throwing :exc:`OverflowError`
+when using :meth:`_ssl._SSLSocket.write` and :meth:`_ssl._SSLSocket.read`
+for a big value of the ``len`` parameter. Patch by Pablo Galindo
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index ad5269d7b07b6..84cc3697b0706 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -2346,7 +2346,7 @@ _ssl__SSLSocket_write_impl(PySSLSocket *self, Py_buffer *b)
do {
PySSL_BEGIN_ALLOW_THREADS
- retval = SSL_write_ex(self->ssl, b->buf, (int)b->len, &count);
+ retval = SSL_write_ex(self->ssl, b->buf, (size_t)b->len, &count);
err = _PySSL_errno(retval == 0, self->ssl, retval);
PySSL_END_ALLOW_THREADS
self->err = err;
@@ -2418,7 +2418,7 @@ _ssl__SSLSocket_pending_impl(PySSLSocket *self)
/*[clinic input]
_ssl._SSLSocket.read
- size as len: int
+ size as len: Py_ssize_t
[
buffer: Py_buffer(accept={rwbuffer})
]
@@ -2428,9 +2428,9 @@ Read up to size bytes from the SSL socket.
[clinic start generated code]*/
static PyObject *
-_ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1,
- Py_buffer *buffer)
-/*[clinic end generated code: output=00097776cec2a0af input=ff157eb918d0905b]*/
+_ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len,
+ int group_right_1, Py_buffer *buffer)
+/*[clinic end generated code: output=49b16e6406023734 input=ec48bf622be1c4a1]*/
{
PyObject *dest = NULL;
char *mem;
@@ -2498,7 +2498,7 @@ _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1,
do {
PySSL_BEGIN_ALLOW_THREADS
- retval = SSL_read_ex(self->ssl, mem, len, &count);
+ retval = SSL_read_ex(self->ssl, mem, (size_t)len, &count);
err = _PySSL_errno(retval == 0, self->ssl, retval);
PySSL_END_ALLOW_THREADS
self->err = err;
diff --git a/Modules/clinic/_ssl.c.h b/Modules/clinic/_ssl.c.h
index b153c30cf39ae..b59b129af8a09 100644
--- a/Modules/clinic/_ssl.c.h
+++ b/Modules/clinic/_ssl.c.h
@@ -271,25 +271,25 @@ PyDoc_STRVAR(_ssl__SSLSocket_read__doc__,
{"read", (PyCFunction)_ssl__SSLSocket_read, METH_VARARGS, _ssl__SSLSocket_read__doc__},
static PyObject *
-_ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1,
- Py_buffer *buffer);
+_ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len,
+ int group_right_1, Py_buffer *buffer);
static PyObject *
_ssl__SSLSocket_read(PySSLSocket *self, PyObject *args)
{
PyObject *return_value = NULL;
- int len;
+ Py_ssize_t len;
int group_right_1 = 0;
Py_buffer buffer = {NULL, NULL};
switch (PyTuple_GET_SIZE(args)) {
case 1:
- if (!PyArg_ParseTuple(args, "i:read", &len)) {
+ if (!PyArg_ParseTuple(args, "n:read", &len)) {
goto exit;
}
break;
case 2:
- if (!PyArg_ParseTuple(args, "iw*:read", &len, &buffer)) {
+ if (!PyArg_ParseTuple(args, "nw*:read", &len, &buffer)) {
goto exit;
}
group_right_1 = 1;
@@ -1358,4 +1358,4 @@ _ssl_enum_crls(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje
#ifndef _SSL_ENUM_CRLS_METHODDEF
#define _SSL_ENUM_CRLS_METHODDEF
#endif /* !defined(_SSL_ENUM_CRLS_METHODDEF) */
-/*[clinic end generated code: output=3b6f4471fb187d85 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=5a7d7bf5cf8ee092 input=a9049054013a1b77]*/
More information about the Python-checkins
mailing list