diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-08-21 11:53:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-21 11:53:05 (GMT) |
commit | ed67e60f48d4e2d881eab0ab12e31e259b126f28 (patch) | |
tree | 983398bd944a6920da4a614f34f09e655be7a399 /Python | |
parent | be9965308022733bc7b0412a99da9fc80c6c7bef (diff) | |
download | cpython-ed67e60f48d4e2d881eab0ab12e31e259b126f28.zip cpython-ed67e60f48d4e2d881eab0ab12e31e259b126f28.tar.gz cpython-ed67e60f48d4e2d881eab0ab12e31e259b126f28.tar.bz2 |
[3.11] gh-107916: Save the error code before decoding the filename in PyErr_SetFromErrnoWithFilename() etc (GH-107929) (GH-108206)
(cherry picked from commit 80bdebdd8593f007a2232ec04a7729bba6ebf12c)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Python')
-rw-r--r-- | Python/errors.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Python/errors.c b/Python/errors.c index d693f3a..8e150c3 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -856,10 +856,12 @@ PyErr_SetFromErrnoWithFilename(PyObject *exc, const char *filename) { PyObject *name = NULL; if (filename) { + int i = errno; name = PyUnicode_DecodeFSDefault(filename); if (name == NULL) { return NULL; } + errno = i; } PyObject *result = PyErr_SetFromErrnoWithFilenameObjects(exc, name, NULL); Py_XDECREF(name); @@ -959,6 +961,9 @@ PyObject *PyErr_SetExcFromWindowsErrWithFilename( { PyObject *name = NULL; if (filename) { + if ((DWORD)ierr == 0) { + ierr = (int)GetLastError(); + } name = PyUnicode_DecodeFSDefault(filename); if (name == NULL) { return NULL; @@ -989,6 +994,9 @@ PyObject *PyErr_SetFromWindowsErrWithFilename( { PyObject *name = NULL; if (filename) { + if ((DWORD)ierr == 0) { + ierr = (int)GetLastError(); + } name = PyUnicode_DecodeFSDefault(filename); if (name == NULL) { return NULL; |