diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-08-21 11:16:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-21 11:16:31 (GMT) |
commit | 80bdebdd8593f007a2232ec04a7729bba6ebf12c (patch) | |
tree | 18b406c41aef8db030841fc066b3a9dc303cfa60 /Python/errors.c | |
parent | acbd3f9c5c5f23e95267714e41236140d84fe962 (diff) | |
download | cpython-80bdebdd8593f007a2232ec04a7729bba6ebf12c.zip cpython-80bdebdd8593f007a2232ec04a7729bba6ebf12c.tar.gz cpython-80bdebdd8593f007a2232ec04a7729bba6ebf12c.tar.bz2 |
gh-107916: Save the error code before decoding the filename in PyErr_SetFromErrnoWithFilename() etc (GH-107929)
Diffstat (limited to 'Python/errors.c')
-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 d9086c5..fb5b3ff 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -895,10 +895,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); @@ -998,6 +1000,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; @@ -1028,6 +1033,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; |