diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-08-26 21:35:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-26 21:35:06 (GMT) |
commit | 2b15536fa94d07e9e286826c23507402313ec7f4 (patch) | |
tree | bed59616b5e2b833e15cc6b10f0dccfca8faa9fb /Python | |
parent | e407cea1938b80b1d469f148a4ea65587820e3eb (diff) | |
download | cpython-2b15536fa94d07e9e286826c23507402313ec7f4.zip cpython-2b15536fa94d07e9e286826c23507402313ec7f4.tar.gz cpython-2b15536fa94d07e9e286826c23507402313ec7f4.tar.bz2 |
gh-107913: Fix possible losses of OSError error codes (GH-107930)
Functions like PyErr_SetFromErrno() and SetFromWindowsErr() should be
called immediately after using the C API which sets errno or the Windows
error code.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/fileutils.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c index 9c49983..9bc1de2 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -1790,6 +1790,7 @@ _Py_fopen_obj(PyObject *path, const char *mode) Py_END_ALLOW_THREADS } while (f == NULL && errno == EINTR && !(async_err = PyErr_CheckSignals())); + int saved_errno = errno; PyMem_Free(wpath); #else PyObject *bytes; @@ -1812,13 +1813,14 @@ _Py_fopen_obj(PyObject *path, const char *mode) Py_END_ALLOW_THREADS } while (f == NULL && errno == EINTR && !(async_err = PyErr_CheckSignals())); - + int saved_errno = errno; Py_DECREF(bytes); #endif if (async_err) return NULL; if (f == NULL) { + errno = saved_errno; PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path); return NULL; } |