summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-08-26 21:35:06 (GMT)
committerGitHub <noreply@github.com>2023-08-26 21:35:06 (GMT)
commit2b15536fa94d07e9e286826c23507402313ec7f4 (patch)
treebed59616b5e2b833e15cc6b10f0dccfca8faa9fb /Python
parente407cea1938b80b1d469f148a4ea65587820e3eb (diff)
downloadcpython-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.c4
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;
}