mirror of
https://github.com/python/cpython.git
synced 2025-08-09 19:38:42 +00:00
[3.12] gh-107913: Fix possible losses of OSError error codes (GH-107930) (#108523)
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.
(cherry picked from commit 2b15536fa9
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
bbdd8895a5
commit
3e20303717
17 changed files with 129 additions and 75 deletions
|
@ -5401,8 +5401,8 @@ sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto,
|
|||
}
|
||||
|
||||
if (!SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0)) {
|
||||
closesocket(fd);
|
||||
PyErr_SetFromWindowsErr(0);
|
||||
closesocket(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -5616,8 +5616,9 @@ socket_gethostname(PyObject *self, PyObject *unused)
|
|||
name,
|
||||
&size))
|
||||
{
|
||||
PyErr_SetFromWindowsErr(0);
|
||||
PyMem_Free(name);
|
||||
return PyErr_SetFromWindowsErr(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = PyUnicode_FromWideChar(name, size);
|
||||
|
@ -6215,8 +6216,8 @@ socket_dup(PyObject *self, PyObject *fdobj)
|
|||
}
|
||||
|
||||
if (!SetHandleInformation((HANDLE)newfd, HANDLE_FLAG_INHERIT, 0)) {
|
||||
closesocket(newfd);
|
||||
PyErr_SetFromWindowsErr(0);
|
||||
closesocket(newfd);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
|
@ -6663,11 +6664,12 @@ socket_inet_ntop(PyObject *self, PyObject *args)
|
|||
|
||||
/* inet_ntop guarantee NUL-termination of resulting string. */
|
||||
retval = inet_ntop(af, packed_ip.buf, ip, sizeof(ip));
|
||||
PyBuffer_Release(&packed_ip);
|
||||
if (!retval) {
|
||||
PyErr_SetFromErrno(PyExc_OSError);
|
||||
PyBuffer_Release(&packed_ip);
|
||||
return NULL;
|
||||
} else {
|
||||
PyBuffer_Release(&packed_ip);
|
||||
return PyUnicode_FromString(retval);
|
||||
}
|
||||
}
|
||||
|
@ -7006,8 +7008,8 @@ socket_if_nameindex(PyObject *self, PyObject *arg)
|
|||
|
||||
ni = if_nameindex();
|
||||
if (ni == NULL) {
|
||||
Py_DECREF(list);
|
||||
PyErr_SetFromErrno(PyExc_OSError);
|
||||
Py_DECREF(list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue