Skip to content

Commit 7dc4d46

Browse files
committed
follow up on 0c992792220bbfb375d5dc8222beb2a55da8441a
1 parent 5fa1cd2 commit 7dc4d46

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

win32/select.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ PHPAPI int php_select(php_socket_t max_fd, fd_set *rfds, fd_set *wfds, fd_set *e
4646
struct timeval tvslice;
4747
int retcode;
4848

49+
/* As max_fd is unsigned, non socket might overflow. */
50+
if (max_fd > (php_socket_t)INT_MAX) {
51+
return -1;
52+
}
53+
4954
#define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set))
5055

5156
/* calculate how long we need to wait in milliseconds */
@@ -61,7 +66,7 @@ PHPAPI int php_select(php_socket_t max_fd, fd_set *rfds, fd_set *wfds, fd_set *e
6166
FD_ZERO(&sock_except);
6267

6368
/* build an array of handles for non-sockets */
64-
for (i = 0; i < INT_MAX && i < max_fd; i++) {
69+
for (i = 0; i < max_fd; i++) {
6570
if (SAFE_FD_ISSET(i, rfds) || SAFE_FD_ISSET(i, wfds) || SAFE_FD_ISSET(i, efds)) {
6671
handles[n_handles] = (HANDLE)(zend_uintptr_t)_get_osfhandle(i);
6772
if (handles[n_handles] == INVALID_HANDLE_VALUE) {
@@ -87,7 +92,7 @@ PHPAPI int php_select(php_socket_t max_fd, fd_set *rfds, fd_set *wfds, fd_set *e
8792

8893
if (n_handles == 0) {
8994
/* plain sockets only - let winsock handle the whole thing */
90-
return select(0, rfds, wfds, efds, tv);
95+
return select(-1, rfds, wfds, efds, tv);
9196
}
9297

9398
/* mixture of handles and sockets; lets multiplex between
@@ -111,7 +116,7 @@ PHPAPI int php_select(php_socket_t max_fd, fd_set *rfds, fd_set *wfds, fd_set *e
111116
tvslice.tv_sec = 0;
112117
tvslice.tv_usec = 100000;
113118

114-
retcode = select(0, &aread, &awrite, &aexcept, &tvslice);
119+
retcode = select(-1, &aread, &awrite, &aexcept, &tvslice);
115120
}
116121
if (n_handles > 0) {
117122
/* check handles */

0 commit comments

Comments
 (0)