gh-107916: Save the error code before decoding the filename in PyErr_SetFromErrnoWithFilename() etc (GH-107929)

This commit is contained in:
Serhiy Storchaka 2023-08-21 14:16:31 +03:00 committed by GitHub
parent acbd3f9c5c
commit 80bdebdd85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -0,0 +1,4 @@
C API functions :c:func:`PyErr_SetFromErrnoWithFilename`,
:c:func:`PyErr_SetExcFromWindowsErrWithFilename` and
:c:func:`PyErr_SetFromWindowsErrWithFilename` save now the error code before
calling :c:func:`PyUnicode_DecodeFSDefault`.

View File

@ -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;