Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-144206: Improve error messages for buffer overflow in fcntl.fcntl() and fcntl.ioctl()#144273

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
serhiy-storchaka wants to merge2 commits intopython:main
base:main
Choose a base branch
Loading
fromserhiy-storchaka:fcntl-buffer-overflow-errmsg
Open
Show file tree
Hide file tree
Changes fromall 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Improve error messages for buffer overflow in :func:`fcntl.fcntl` and
:func:`fcntl.ioctl`.
31 changes: 26 additions & 5 deletionsModules/fcntlmodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -111,7 +111,11 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
return !async_err ? PyErr_SetFromErrno(PyExc_OSError) : NULL;
}
if (memcmp(buf + len, guard, GUARDSZ) != 0) {
PyErr_SetString(PyExc_SystemError, "buffer overflow");
PyErr_SetString(PyExc_SystemError,
"Possible stack corruption in fcntl() due to "
"buffer overflow. "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why do you use a different message for the memcmp() case? It's not a "Memory corruption" here as well?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It depends whether the buffer was on the stack or in the heap memory (preallocated bytes object).

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It depends whether the buffer was on the stack or in the heap memory (preallocated bytes object).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Oh ok, it makes sense. I didn't notice that one code path allocated memory on the stack.

"Provide an argument of sufficient size as "
"determined by the operation.");
return NULL;
}
return PyBytes_FromStringAndSize(buf, len);
Expand DownExpand Up@@ -139,7 +143,11 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
return NULL;
}
if (ptr[len] != '\0') {
PyErr_SetString(PyExc_SystemError, "buffer overflow");
PyErr_SetString(PyExc_SystemError,
"Memory corruption in fcntl() due to "
"buffer overflow. "
"Provide an argument of sufficient size as "
"determined by the operation.");
PyBytesWriter_Discard(writer);
return NULL;
}
Expand DownExpand Up@@ -264,7 +272,12 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned long code, PyObject *arg,
}
PyBuffer_Release(&view);
if (ptr == buf && memcmp(buf + len, guard, GUARDSZ) != 0) {
PyErr_SetString(PyExc_SystemError, "buffer overflow");
PyErr_SetString(PyExc_SystemError,
"Possible stack corruption in ioctl() due to "
"buffer overflow. "
"Provide a writable buffer argument of "
"sufficient size as determined by "
"the operation.");
return NULL;
}
return PyLong_FromLong(ret);
Expand DownExpand Up@@ -293,7 +306,11 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned long code, PyObject *arg,
return !async_err ? PyErr_SetFromErrno(PyExc_OSError) : NULL;
}
if (memcmp(buf + len, guard, GUARDSZ) != 0) {
PyErr_SetString(PyExc_SystemError, "buffer overflow");
PyErr_SetString(PyExc_SystemError,
"Possible stack corruption in ioctl() due to "
"buffer overflow. "
"Provide an argument of sufficient size as "
"determined by the operation.");
return NULL;
}
return PyBytes_FromStringAndSize(buf, len);
Expand DownExpand Up@@ -321,7 +338,11 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned long code, PyObject *arg,
return NULL;
}
if (ptr[len] != '\0') {
PyErr_SetString(PyExc_SystemError, "buffer overflow");
PyErr_SetString(PyExc_SystemError,
"Memory corruption in ioctl() due to "
"buffer overflow. "
"Provide an argument of sufficient size as "
"determined by the operation.");
PyBytesWriter_Discard(writer);
return NULL;
}
Expand Down
Loading

[8]ページ先頭

©2009-2026 Movatter.jp