diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-08-27 12:18:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-27 12:18:58 (GMT) |
commit | b9fc5363997c0cbb78a8d654f9bf6cac1fc056df (patch) | |
tree | f63833fb348e102e5eb9ab296cd7acbeca861879 /Python | |
parent | 8a275f7c0120c6ebd1cabe2ddba38c2c6a33c958 (diff) | |
download | cpython-b9fc5363997c0cbb78a8d654f9bf6cac1fc056df.zip cpython-b9fc5363997c0cbb78a8d654f9bf6cac1fc056df.tar.gz cpython-b9fc5363997c0cbb78a8d654f9bf6cac1fc056df.tar.bz2 |
[3.11] gh-107913: Fix possible losses of OSError error codes (GH-107930) (GH-108524)
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)
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 b310a6c..24341dd 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -1687,6 +1687,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; #if !USE_UNICODE_WCHAR_CACHE PyMem_Free(wpath); #endif /* USE_UNICODE_WCHAR_CACHE */ @@ -1711,13 +1712,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; } |