mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-134744: Fix fcntl error handling (#134748)
Fix also reference leak on buffer overflow.
This commit is contained in:
parent
176b059fa0
commit
9300a596d3
3 changed files with 28 additions and 4 deletions
|
@ -128,7 +128,7 @@ 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) {
|
||||
if (async_err) {
|
||||
if (!async_err) {
|
||||
PyErr_SetFromErrno(PyExc_OSError);
|
||||
}
|
||||
Py_DECREF(result);
|
||||
|
@ -136,6 +136,7 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
|
|||
}
|
||||
if (ptr[len] != '\0') {
|
||||
PyErr_SetString(PyExc_SystemError, "buffer overflow");
|
||||
Py_DECREF(result);
|
||||
return NULL;
|
||||
}
|
||||
return result;
|
||||
|
@ -310,7 +311,7 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned long code, PyObject *arg,
|
|||
Py_END_ALLOW_THREADS
|
||||
} while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
|
||||
if (ret < 0) {
|
||||
if (async_err) {
|
||||
if (!async_err) {
|
||||
PyErr_SetFromErrno(PyExc_OSError);
|
||||
}
|
||||
Py_DECREF(result);
|
||||
|
@ -318,6 +319,7 @@ fcntl_ioctl_impl(PyObject *module, int fd, unsigned long code, PyObject *arg,
|
|||
}
|
||||
if (ptr[len] != '\0') {
|
||||
PyErr_SetString(PyExc_SystemError, "buffer overflow");
|
||||
Py_DECREF(result);
|
||||
return NULL;
|
||||
}
|
||||
return result;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue