Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b6dab6b

Browse files
committed
Issue #22042: Avoid dangerous C cast in socket.setblocking()
Avoid cast from (int*) to (u_long*), even if sizeof(int) == sizeof(u_long).
1 parent baddc84 commit b6dab6b

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

Modules/socketmodule.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,9 @@ set_gaierror(int error)
548548
static int
549549
internal_setblocking(PySocketSockObject *s, int block)
550550
{
551+
#ifdef MS_WINDOWS
552+
u_long arg;
553+
#endif
551554
#if !defined(MS_WINDOWS) \
552555
&& !((defined(HAVE_SYS_IOCTL_H) && defined(FIONBIO)))
553556
int delay_flag, new_delay_flag;
@@ -574,8 +577,8 @@ internal_setblocking(PySocketSockObject *s, int block)
574577
fcntl(s->sock_fd, F_SETFL, new_delay_flag);
575578
#endif
576579
#else /* MS_WINDOWS */
577-
block = !block;
578-
ioctlsocket(s->sock_fd, FIONBIO, (u_long*)&block);
580+
arg = !block;
581+
ioctlsocket(s->sock_fd, FIONBIO, &arg);
579582
#endif /* MS_WINDOWS */
580583
Py_END_ALLOW_THREADS
581584

0 commit comments

Comments
 (0)