summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-07-23 20:56:55 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-07-23 20:56:55 (GMT)
commitb6dab6bce83bc64d07abb9eeb9daec461414bc08 (patch)
treecc174608ff79a2ef089fe227bac34d9205135bec /Modules
parentbaddc840d5e3bb5ca5b48b0ae9f93bea09b35f19 (diff)
downloadcpython-b6dab6bce83bc64d07abb9eeb9daec461414bc08.zip
cpython-b6dab6bce83bc64d07abb9eeb9daec461414bc08.tar.gz
cpython-b6dab6bce83bc64d07abb9eeb9daec461414bc08.tar.bz2
Issue #22042: Avoid dangerous C cast in socket.setblocking()
Avoid cast from (int*) to (u_long*), even if sizeof(int) == sizeof(u_long).
Diffstat (limited to 'Modules')
-rw-r--r--Modules/socketmodule.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 780447c..f510f0e 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -548,6 +548,9 @@ set_gaierror(int error)
static int
internal_setblocking(PySocketSockObject *s, int block)
{
+#ifdef MS_WINDOWS
+ u_long arg;
+#endif
#if !defined(MS_WINDOWS) \
&& !((defined(HAVE_SYS_IOCTL_H) && defined(FIONBIO)))
int delay_flag, new_delay_flag;
@@ -574,8 +577,8 @@ internal_setblocking(PySocketSockObject *s, int block)
fcntl(s->sock_fd, F_SETFL, new_delay_flag);
#endif
#else /* MS_WINDOWS */
- block = !block;
- ioctlsocket(s->sock_fd, FIONBIO, (u_long*)&block);
+ arg = !block;
+ ioctlsocket(s->sock_fd, FIONBIO, &arg);
#endif /* MS_WINDOWS */
Py_END_ALLOW_THREADS