Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Improve error messages for buffer overflow in :func:`fcntl.fcntl` and | ||
| :func:`fcntl.ioctl`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, | ||
| "Possible stack corruption in fcntl() due to " | ||
| "buffer overflow. " | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). Member There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| @@ -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, | ||
| "Memory corruption in fcntl() due to " | ||
| "buffer overflow. " | ||
| "Provide an argument of sufficient size as " | ||
| "determined by the operation."); | ||
| PyBytesWriter_Discard(writer); | ||
| return NULL; | ||
| } | ||
| @@ -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, | ||
| "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); | ||
| @@ -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, | ||
| "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); | ||
| @@ -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, | ||
| "Memory corruption in ioctl() due to " | ||
| "buffer overflow. " | ||
| "Provide an argument of sufficient size as " | ||
| "determined by the operation."); | ||
| PyBytesWriter_Discard(writer); | ||
| return NULL; | ||
| } | ||
Uh oh!
There was an error while loading.Please reload this page.