diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-08-26 23:24:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-26 23:24:40 (GMT) |
commit | 3e2030371723e5fb7c9ccbe83cd980ce69cabc1a (patch) | |
tree | 16a5ba8999b1440a494153cd76e5a71a779ebb28 /Python | |
parent | bbdd8895a5aced4cd4e66a5c6e3471636f28df6b (diff) | |
download | cpython-3e2030371723e5fb7c9ccbe83cd980ce69cabc1a.zip cpython-3e2030371723e5fb7c9ccbe83cd980ce69cabc1a.tar.gz cpython-3e2030371723e5fb7c9ccbe83cd980ce69cabc1a.tar.bz2 |
[3.12] gh-107913: Fix possible losses of OSError error codes (GH-107930) (#108523)
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.
(cherry picked from commit 2b15536fa94d07e9e286826c23507402313ec7f4)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
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 268ffa3..610e729 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; } |