From e041b2ba2ffffae2dbfbaebfc662b158cd089e65 Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Fri, 29 Jul 2022 15:59:00 +0300 Subject: [PATCH 1/8] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20fcntl=5Ffcntl=5Fimpl=20=D0=B8=20fcntl=5Fioctl=5Fimpl.?= =?UTF-8?q?=20=D0=94=D0=BB=D1=8F=20=D1=82=D0=B5=D1=81=D1=82=D0=B0=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=B4=D0=B2=D0=B0=20=D1=80=D0=B0=D0=B7=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82=D0=B0=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Modules/fcntlmodule.c | 52 +++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c index 9a8ec8dc9858d7..75c0ea47c8be0f 100644 --- a/Modules/fcntlmodule.c +++ b/Modules/fcntlmodule.c @@ -54,7 +54,7 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) int ret; char *str; Py_ssize_t len; - char buf[1024]; + //char buf[1024]; int async_err = 0; if (PySys_Audit("fcntl.fcntl", "iiO", fd, code, arg ? arg : Py_None) < 0) { @@ -65,11 +65,23 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) int parse_result; if (PyArg_Parse(arg, "s#", &str, &len)) { - if ((size_t)len > sizeof buf) { + /*if ((size_t)len > sizeof buf) { PyErr_SetString(PyExc_ValueError, "fcntl string arg too long"); return NULL; + }*/ + char* buf = malloc((size_t)len); + PyObject* buf_ret; + if(buf == NULL) { + PyErr_NoMemory(); + return NULL; + } + /*PyObject *o = PyBytes_FromStringAndSize(NULL, len); + if (o == NULL) { + return NULL; } + char *buf = PyBytes_AS_STRING(o);*/ + memcpy(buf, str, len); do { Py_BEGIN_ALLOW_THREADS @@ -77,9 +89,13 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) Py_END_ALLOW_THREADS } while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals())); if (ret < 0) { + free(buf); return !async_err ? PyErr_SetFromErrno(PyExc_OSError) : NULL; } - return PyBytes_FromStringAndSize(buf, len); + //return PyBytes_FromStringAndSize(buf, len); + buf_ret = PyBytes_FromStringAndSize(buf, len); + free(buf); + return(buf_ret); } PyErr_Clear(); @@ -148,7 +164,7 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code, PyObject *ob_arg, int mutate_arg) /*[clinic end generated code: output=7f7f5840c65991be input=967b4a4cbeceb0a8]*/ { -#define IOCTL_BUFSZ 1024 +//#define IOCTL_BUFSZ 1024 /* We use the unsigned non-checked 'I' format for the 'code' parameter because the system expects it to be a 32bit bit field value regardless of it being passed as an int or unsigned long on @@ -164,7 +180,7 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code, Py_buffer pstr; char *str; Py_ssize_t len; - char buf[IOCTL_BUFSZ+1]; /* argument plus NUL byte */ + //char buf[IOCTL_BUFSZ+1]; /* argument plus NUL byte */ if (PySys_Audit("fcntl.ioctl", "iIO", fd, code, ob_arg ? ob_arg : Py_None) < 0) { @@ -177,24 +193,30 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code, str = pstr.buf; len = pstr.len; + PyObject *o = PyBytes_FromStringAndSize(NULL, len); + if (o == NULL) { + return NULL; + } + char *buf = PyBytes_AS_STRING(o); + if (mutate_arg) { - if (len <= IOCTL_BUFSZ) { + /*if (len <= IOCTL_BUFSZ) */{ memcpy(buf, str, len); buf[len] = '\0'; arg = buf; } - else { + /*else { arg = str; - } + }*/ } else { - if (len > IOCTL_BUFSZ) { + /*if (len > IOCTL_BUFSZ) { PyBuffer_Release(&pstr); PyErr_SetString(PyExc_ValueError, "ioctl string arg too long"); return NULL; } - else { + else */{ memcpy(buf, str, len); buf[len] = '\0'; arg = buf; @@ -208,7 +230,7 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code, else { ret = ioctl(fd, code, arg); } - if (mutate_arg && (len <= IOCTL_BUFSZ)) { + if (mutate_arg /*&& (len <= IOCTL_BUFSZ)*/) { memcpy(str, buf, len); } PyBuffer_Release(&pstr); /* No further access to str below this point */ @@ -228,12 +250,18 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code, if (PyArg_Parse(ob_arg, "s*:ioctl", &pstr)) { str = pstr.buf; len = pstr.len; - if (len > IOCTL_BUFSZ) { + /*if (len > IOCTL_BUFSZ) { PyBuffer_Release(&pstr); PyErr_SetString(PyExc_ValueError, "ioctl string arg too long"); return NULL; + }*/ + PyObject *o = PyBytes_FromStringAndSize(NULL, len); + if (o == NULL) { + return NULL; } + char *buf = PyBytes_AS_STRING(o); + memcpy(buf, str, len); buf[len] = '\0'; Py_BEGIN_ALLOW_THREADS From 8fbddd5c3972319296dfa4d87476d633fb0b693a Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Fri, 29 Jul 2022 17:44:18 +0300 Subject: [PATCH 2/8] =?UTF-8?q?=D0=9E=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=D1=81=D1=8F=20=D0=BD=D0=B0=20=D0=B2=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=B0=D0=BD=D1=82=D0=B5=20=D1=81=20PyBytes=5FFromStringA?= =?UTF-8?q?ndSize.=20=D0=92=20fcntl=5Fioctl=5Fimpl=20=D1=83=D0=B1=D1=80?= =?UTF-8?q?=D0=B0=D0=BB=20buf[len]=20=3D=20'\0';?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Modules/fcntlmodule.c | 78 ++++++++----------------------------------- 1 file changed, 13 insertions(+), 65 deletions(-) diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c index 75c0ea47c8be0f..28f0c9819ac99c 100644 --- a/Modules/fcntlmodule.c +++ b/Modules/fcntlmodule.c @@ -40,9 +40,8 @@ as constants in the fcntl module, using the same names as used in the relevant C header files. The argument arg is optional, and defaults to 0; it may be an int or a string. If arg is given as a string, the return value of fcntl is a string of that length, containing the -resulting value put in the arg buffer by the operating system. The length -of the arg string is not allowed to exceed 1024 bytes. If the arg given -is an integer or if none is specified, the result value is an integer +resulting value put in the arg buffer by the operating system. If the arg +given is an integer or if none is specified, the result value is an integer corresponding to the return value of the fcntl call in the C code. [clinic start generated code]*/ @@ -54,7 +53,6 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) int ret; char *str; Py_ssize_t len; - //char buf[1024]; int async_err = 0; if (PySys_Audit("fcntl.fcntl", "iiO", fd, code, arg ? arg : Py_None) < 0) { @@ -65,22 +63,11 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) int parse_result; if (PyArg_Parse(arg, "s#", &str, &len)) { - /*if ((size_t)len > sizeof buf) { - PyErr_SetString(PyExc_ValueError, - "fcntl string arg too long"); - return NULL; - }*/ - char* buf = malloc((size_t)len); - PyObject* buf_ret; - if(buf == NULL) { - PyErr_NoMemory(); - return NULL; - } - /*PyObject *o = PyBytes_FromStringAndSize(NULL, len); + PyObject *o = PyBytes_FromStringAndSize(NULL, len); if (o == NULL) { return NULL; } - char *buf = PyBytes_AS_STRING(o);*/ + char *buf = PyBytes_AS_STRING(o); memcpy(buf, str, len); do { @@ -89,13 +76,9 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) Py_END_ALLOW_THREADS } while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals())); if (ret < 0) { - free(buf); return !async_err ? PyErr_SetFromErrno(PyExc_OSError) : NULL; } - //return PyBytes_FromStringAndSize(buf, len); - buf_ret = PyBytes_FromStringAndSize(buf, len); - free(buf); - return(buf_ret); + return PyBytes_FromStringAndSize(buf, len); } PyErr_Clear(); @@ -151,8 +134,7 @@ the behavior is as if a string had been passed. If the argument is an immutable buffer (most likely a string) then a copy of the buffer is passed to the operating system and the return value is a string of the same length containing whatever the operating system put in -the buffer. The length of the arg buffer in this case is not allowed to -exceed 1024 bytes. +the buffer. If the arg given is an integer or if none is specified, the result value is an integer corresponding to the return value of the ioctl call in the C @@ -164,7 +146,6 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code, PyObject *ob_arg, int mutate_arg) /*[clinic end generated code: output=7f7f5840c65991be input=967b4a4cbeceb0a8]*/ { -//#define IOCTL_BUFSZ 1024 /* We use the unsigned non-checked 'I' format for the 'code' parameter because the system expects it to be a 32bit bit field value regardless of it being passed as an int or unsigned long on @@ -180,7 +161,6 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code, Py_buffer pstr; char *str; Py_ssize_t len; - //char buf[IOCTL_BUFSZ+1]; /* argument plus NUL byte */ if (PySys_Audit("fcntl.ioctl", "iIO", fd, code, ob_arg ? ob_arg : Py_None) < 0) { @@ -189,7 +169,6 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code, if (ob_arg != NULL) { if (PyArg_Parse(ob_arg, "w*:ioctl", &pstr)) { - char *arg; str = pstr.buf; len = pstr.len; @@ -199,38 +178,13 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code, } char *buf = PyBytes_AS_STRING(o); + memcpy(buf, str, len); + + Py_BEGIN_ALLOW_THREADS /* think array.resize() */ + ret = ioctl(fd, code, buf); + Py_END_ALLOW_THREADS + if (mutate_arg) { - /*if (len <= IOCTL_BUFSZ) */{ - memcpy(buf, str, len); - buf[len] = '\0'; - arg = buf; - } - /*else { - arg = str; - }*/ - } - else { - /*if (len > IOCTL_BUFSZ) { - PyBuffer_Release(&pstr); - PyErr_SetString(PyExc_ValueError, - "ioctl string arg too long"); - return NULL; - } - else */{ - memcpy(buf, str, len); - buf[len] = '\0'; - arg = buf; - } - } - if (buf == arg) { - Py_BEGIN_ALLOW_THREADS /* think array.resize() */ - ret = ioctl(fd, code, arg); - Py_END_ALLOW_THREADS - } - else { - ret = ioctl(fd, code, arg); - } - if (mutate_arg /*&& (len <= IOCTL_BUFSZ)*/) { memcpy(str, buf, len); } PyBuffer_Release(&pstr); /* No further access to str below this point */ @@ -250,12 +204,7 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code, if (PyArg_Parse(ob_arg, "s*:ioctl", &pstr)) { str = pstr.buf; len = pstr.len; - /*if (len > IOCTL_BUFSZ) { - PyBuffer_Release(&pstr); - PyErr_SetString(PyExc_ValueError, - "ioctl string arg too long"); - return NULL; - }*/ + PyObject *o = PyBytes_FromStringAndSize(NULL, len); if (o == NULL) { return NULL; @@ -263,7 +212,6 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code, char *buf = PyBytes_AS_STRING(o); memcpy(buf, str, len); - buf[len] = '\0'; Py_BEGIN_ALLOW_THREADS ret = ioctl(fd, code, buf); Py_END_ALLOW_THREADS From d5d5746184ddf61c84ea8d8e591a14b8517ded76 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Fri, 29 Jul 2022 18:23:50 +0300 Subject: [PATCH 3/8] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D1=82=D1=8C=20fcnt?= =?UTF-8?q?l=5Ffcntl=5Fimpl=20=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D0=B8=D0=B2?= =?UTF-8?q?=20fcntl=5Fioctl=5Fimpl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Пулл-реквест gh-95429 внёс по сути те же изменения, так что фокусируемся на отсутствующем там fcntl_ioctl_impl. --- Modules/fcntlmodule.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c index 28f0c9819ac99c..f38fb09e5dbc8d 100644 --- a/Modules/fcntlmodule.c +++ b/Modules/fcntlmodule.c @@ -40,8 +40,9 @@ as constants in the fcntl module, using the same names as used in the relevant C header files. The argument arg is optional, and defaults to 0; it may be an int or a string. If arg is given as a string, the return value of fcntl is a string of that length, containing the -resulting value put in the arg buffer by the operating system. If the arg -given is an integer or if none is specified, the result value is an integer +resulting value put in the arg buffer by the operating system. The length +of the arg string is not allowed to exceed 1024 bytes. If the arg given +is an integer or if none is specified, the result value is an integer corresponding to the return value of the fcntl call in the C code. [clinic start generated code]*/ @@ -53,6 +54,7 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) int ret; char *str; Py_ssize_t len; + //char buf[1024]; int async_err = 0; if (PySys_Audit("fcntl.fcntl", "iiO", fd, code, arg ? arg : Py_None) < 0) { @@ -63,11 +65,22 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) int parse_result; if (PyArg_Parse(arg, "s#", &str, &len)) { - PyObject *o = PyBytes_FromStringAndSize(NULL, len); + /*if ((size_t)len > sizeof buf) { + PyErr_SetString(PyExc_ValueError, + "fcntl string arg too long"); + return NULL; + }*/ + char* buf = malloc((size_t)len); + PyObject* buf_ret; + if(buf == NULL) { + PyErr_NoMemory(); + return NULL; + } + /*PyObject *o = PyBytes_FromStringAndSize(NULL, len); if (o == NULL) { return NULL; } - char *buf = PyBytes_AS_STRING(o); + char *buf = PyBytes_AS_STRING(o);*/ memcpy(buf, str, len); do { @@ -76,9 +89,13 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) Py_END_ALLOW_THREADS } while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals())); if (ret < 0) { + free(buf); return !async_err ? PyErr_SetFromErrno(PyExc_OSError) : NULL; } - return PyBytes_FromStringAndSize(buf, len); + //return PyBytes_FromStringAndSize(buf, len); + buf_ret = PyBytes_FromStringAndSize(buf, len); + free(buf); + return(buf_ret); } PyErr_Clear(); From 1f0096dee29388f0f50a236537312413875f63b3 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Fri, 29 Jul 2022 18:39:11 +0300 Subject: [PATCH 4/8] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B3=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D1=80=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BE?= =?UTF-8?q?=D0=B1=D1=91=D1=80=D1=82=D0=BA=D1=83,=20=D0=BF=D1=80=D0=B5?= =?UTF-8?q?=D0=BE=D0=B1=D1=80=D0=B0=D0=B7=D1=83=D1=8E=D1=89=D1=83=D1=8E=20?= =?UTF-8?q?=D0=BF=D0=B8=D1=82=D0=BE=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=B7=D0=BE=D0=B2=20=D0=B2=20=D1=81=D0=B8=D1=88=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Консольная команда, использованная для обновления: python Tools/clinic/clinic.py Modules/fcntlmodule.c Если этого не сделать, автоматическая проверка пулл-реквеста увидит рассинхронизацию, и у пул-реквеста в статусах будет крестик напротив "Tests / Check if generated files are up to date". --- Modules/clinic/fcntlmodule.c.h | 5 ++--- Modules/fcntlmodule.c | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Modules/clinic/fcntlmodule.c.h b/Modules/clinic/fcntlmodule.c.h index c41f088ff1528b..fad0d72dc90cb1 100644 --- a/Modules/clinic/fcntlmodule.c.h +++ b/Modules/clinic/fcntlmodule.c.h @@ -79,8 +79,7 @@ PyDoc_STRVAR(fcntl_ioctl__doc__, "If the argument is an immutable buffer (most likely a string) then a copy\n" "of the buffer is passed to the operating system and the return value is a\n" "string of the same length containing whatever the operating system put in\n" -"the buffer. The length of the arg buffer in this case is not allowed to\n" -"exceed 1024 bytes.\n" +"the buffer.\n" "\n" "If the arg given is an integer or if none is specified, the result value is\n" "an integer corresponding to the return value of the ioctl call in the C\n" @@ -243,4 +242,4 @@ fcntl_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=b8cb14ab35de4c6a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=fdcb77f29c5b8df1 input=a9049054013a1b77]*/ diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c index f38fb09e5dbc8d..8bb645e26d1f57 100644 --- a/Modules/fcntlmodule.c +++ b/Modules/fcntlmodule.c @@ -161,7 +161,7 @@ code. static PyObject * fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code, PyObject *ob_arg, int mutate_arg) -/*[clinic end generated code: output=7f7f5840c65991be input=967b4a4cbeceb0a8]*/ +/*[clinic end generated code: output=7f7f5840c65991be input=6b70e7e5a8df40fa]*/ { /* We use the unsigned non-checked 'I' format for the 'code' parameter because the system expects it to be a 32bit bit field value From 6bd428da13c1e6d367a43e584eba2f26751f65be Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Fri, 29 Jul 2022 19:09:49 +0300 Subject: [PATCH 5/8] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BE=D1=82=D0=BC=D0=B5=D0=BD=D1=83=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B9=20=20fnctl=5Ffnctl?= =?UTF-8?q?=5Fimpl=20=D0=B4=D0=BE=20=D0=BA=D0=BE=D0=BD=D1=86=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Modules/fcntlmodule.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c index 8bb645e26d1f57..06df934b749c8c 100644 --- a/Modules/fcntlmodule.c +++ b/Modules/fcntlmodule.c @@ -54,7 +54,7 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) int ret; char *str; Py_ssize_t len; - //char buf[1024]; + char buf[1024]; int async_err = 0; if (PySys_Audit("fcntl.fcntl", "iiO", fd, code, arg ? arg : Py_None) < 0) { @@ -65,23 +65,11 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) int parse_result; if (PyArg_Parse(arg, "s#", &str, &len)) { - /*if ((size_t)len > sizeof buf) { + if ((size_t)len > sizeof buf) { PyErr_SetString(PyExc_ValueError, "fcntl string arg too long"); return NULL; - }*/ - char* buf = malloc((size_t)len); - PyObject* buf_ret; - if(buf == NULL) { - PyErr_NoMemory(); - return NULL; } - /*PyObject *o = PyBytes_FromStringAndSize(NULL, len); - if (o == NULL) { - return NULL; - } - char *buf = PyBytes_AS_STRING(o);*/ - memcpy(buf, str, len); do { Py_BEGIN_ALLOW_THREADS From 971dbf7dea9fb27fab6b2657d2e889b963b3c964 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Fri, 29 Jul 2022 19:13:36 +0300 Subject: [PATCH 6/8] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BE=D1=82=D0=BC=D0=B5=D0=BD=D1=83=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=B8=D0=B7=20?= =?UTF-8?q?=D0=B1=D0=BE=D0=BB=D0=B5=D0=B5=20=D1=80=D0=B0=D0=BD=D0=BD=D0=B8?= =?UTF-8?q?=D1=85=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Modules/fcntlmodule.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c index 06df934b749c8c..65b19de61a9bc0 100644 --- a/Modules/fcntlmodule.c +++ b/Modules/fcntlmodule.c @@ -77,13 +77,9 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) Py_END_ALLOW_THREADS } while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals())); if (ret < 0) { - free(buf); return !async_err ? PyErr_SetFromErrno(PyExc_OSError) : NULL; } - //return PyBytes_FromStringAndSize(buf, len); - buf_ret = PyBytes_FromStringAndSize(buf, len); - free(buf); - return(buf_ret); + return PyBytes_FromStringAndSize(buf, len); } PyErr_Clear(); From 9712107947e34dcacf369f83718e4f94d9532734 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Fri, 29 Jul 2022 19:29:23 +0300 Subject: [PATCH 7/8] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D1=8C=20=D0=B2=20=D0=B6?= =?UTF-8?q?=D1=83=D1=80=D0=BD=D0=B0=D0=BB=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022-07-29-19-28-34.gh-issue-95380.6haDR2.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-07-29-19-28-34.gh-issue-95380.6haDR2.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-07-29-19-28-34.gh-issue-95380.6haDR2.rst b/Misc/NEWS.d/next/Core and Builtins/2022-07-29-19-28-34.gh-issue-95380.6haDR2.rst new file mode 100644 index 00000000000000..6edbd479ab1623 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-07-29-19-28-34.gh-issue-95380.6haDR2.rst @@ -0,0 +1 @@ +Remove max path size limit of 1024 for :func:`fcntl.ioctl` function. From f308606f39d8737f9f19f1a4cfbeee1e9d54ad22 Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Mon, 1 Aug 2022 12:18:22 +0300 Subject: [PATCH 8/8] fcntl_fcntl_impl: Returned as it was, at the request of GST: https://github.com/python/cpython/issues/95380#issuecomment-1199496535 fcntl_ioctl_impl: add Py_DECREF. --- Modules/fcntlmodule.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c index 28f0c9819ac99c..032f2b81f7f63f 100644 --- a/Modules/fcntlmodule.c +++ b/Modules/fcntlmodule.c @@ -53,6 +53,7 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) int ret; char *str; Py_ssize_t len; + char buf[1024]; int async_err = 0; if (PySys_Audit("fcntl.fcntl", "iiO", fd, code, arg ? arg : Py_None) < 0) { @@ -63,12 +64,11 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg) int parse_result; if (PyArg_Parse(arg, "s#", &str, &len)) { - PyObject *o = PyBytes_FromStringAndSize(NULL, len); - if (o == NULL) { + if ((size_t)len > sizeof buf) { + PyErr_SetString(PyExc_ValueError, + "fcntl string arg too long"); return NULL; } - char *buf = PyBytes_AS_STRING(o); - memcpy(buf, str, len); do { Py_BEGIN_ALLOW_THREADS @@ -189,14 +189,16 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code, } PyBuffer_Release(&pstr); /* No further access to str below this point */ if (ret < 0) { + Py_DECREF(o); PyErr_SetFromErrno(PyExc_OSError); return NULL; } if (mutate_arg) { + Py_DECREF(o); return PyLong_FromLong(ret); } else { - return PyBytes_FromStringAndSize(buf, len); + return o; } } @@ -216,12 +218,13 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code, ret = ioctl(fd, code, buf); Py_END_ALLOW_THREADS if (ret < 0) { + Py_DECREF(o); PyBuffer_Release(&pstr); PyErr_SetFromErrno(PyExc_OSError); return NULL; } PyBuffer_Release(&pstr); - return PyBytes_FromStringAndSize(buf, len); + return o; } PyErr_Clear();