Skip to content

gh-95380: Remove limitation of 1024 max path size for fcntl #95429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove max path size limit of 1024 for :func:`fcntl.fcntl` function. Patch by Grégory Starck.
5 changes: 2 additions & 3 deletions Modules/clinic/fcntlmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Modules/fcntlmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,19 @@ 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
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]*/

static PyObject *
fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
/*[clinic end generated code: output=888fc93b51c295bd input=7955340198e5f334]*/
/*[clinic end generated code: output=888fc93b51c295bd input=eed7ab9999c13350]*/
{
unsigned int int_arg = 0;
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) {
Expand All @@ -65,21 +63,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) {
PyErr_SetString(PyExc_ValueError,
"fcntl string arg too long");
PyObject* buf_ret = PyBytes_FromStringAndSize(NULL, len);
if (buf_ret == NULL) {
PyErr_NoMemory();
return NULL;
}
char *buf = PyBytes_AS_STRING(buf_ret);
memcpy(buf, str, len);
do {
Py_BEGIN_ALLOW_THREADS
ret = fcntl(fd, code, buf);
Py_END_ALLOW_THREADS
} while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
if (ret < 0) {
Py_DECREF(buf_ret);
return !async_err ? PyErr_SetFromErrno(PyExc_OSError) : NULL;
}
return PyBytes_FromStringAndSize(buf, len);
return buf_ret;
}

PyErr_Clear();
Expand Down