diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-08-26 23:24:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-26 23:24:40 (GMT) |
commit | 3e2030371723e5fb7c9ccbe83cd980ce69cabc1a (patch) | |
tree | 16a5ba8999b1440a494153cd76e5a71a779ebb28 /Modules/socketmodule.c | |
parent | bbdd8895a5aced4cd4e66a5c6e3471636f28df6b (diff) | |
download | cpython-3e2030371723e5fb7c9ccbe83cd980ce69cabc1a.zip cpython-3e2030371723e5fb7c9ccbe83cd980ce69cabc1a.tar.gz cpython-3e2030371723e5fb7c9ccbe83cd980ce69cabc1a.tar.bz2 |
[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 2b15536fa94d07e9e286826c23507402313ec7f4)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r-- | Modules/socketmodule.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 1ae7ab7..4ec68e2 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -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; } |