mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.11] gh-107913: Fix possible losses of OSError error codes (GH-107930) (GH-108524)
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)
This commit is contained in:
parent
8a275f7c01
commit
b9fc536399
17 changed files with 129 additions and 77 deletions
|
|
@ -5351,8 +5351,8 @@ sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto,
|
|||
|
||||
if (!support_wsa_no_inherit) {
|
||||
if (!SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0)) {
|
||||
closesocket(fd);
|
||||
PyErr_SetFromWindowsErr(0);
|
||||
closesocket(fd);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -5495,8 +5495,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);
|
||||
|
|
@ -6083,8 +6084,8 @@ socket_dup(PyObject *self, PyObject *fdobj)
|
|||
return set_error();
|
||||
|
||||
if (!SetHandleInformation((HANDLE)newfd, HANDLE_FLAG_INHERIT, 0)) {
|
||||
closesocket(newfd);
|
||||
PyErr_SetFromWindowsErr(0);
|
||||
closesocket(newfd);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
|
|
@ -6528,11 +6529,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);
|
||||
}
|
||||
}
|
||||
|
|
@ -6862,8 +6864,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