Skip to content

Commit 5fa1cd2

Browse files
Fleshgrinderweltling
authored andcommitted
Fixed php_socket_t to int conversion
This warning was about a possible loss of data due to the downcast of `php_socket_t` to `int`. The former maps to a platform specific type, hence, it might downcast from a 64 bit integer to a 32 bit intger. Fixed possibly overflowing vars Due to the change from `int` to `php_socket_t` some variables might overflow now. Changed all variables that might be affected. Revert "Fixed possibly overflowing vars" This reverts commit bf64fd5. Use aliased PHP socket type Using the alias protects us from changes to the underlying type. Removed ignored nfds argument The `nfds` argument to the Win32 `select` function is always ignored, regardless of its actual value. Hence, we should not pass it in the first place. See https://msdn.microsoft.com/en-us/library/windows/desktop/ms740141(v=vs.85).aspx for reference. Target value is not a pointer Avoid overflow in loop
1 parent fb6e718 commit 5fa1cd2

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

sapi/cli/php_cli.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ static void print_extensions(void) /* {{{ */
248248
#define STDERR_FILENO 2
249249
#endif
250250

251-
static inline int sapi_cli_select(int fd)
251+
static inline int sapi_cli_select(php_socket_t fd)
252252
{
253253
fd_set wfd, dfd;
254254
struct timeval tv;

win32/select.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* - Calling this with NULL sets as a portable way to sleep with sub-second
3535
* accuracy is not supported.
3636
* */
37-
PHPAPI int php_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv)
37+
PHPAPI int php_select(php_socket_t max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv)
3838
{
3939
ULONGLONG ms_total, limit;
4040
HANDLE handles[MAXIMUM_WAIT_OBJECTS];
@@ -61,7 +61,7 @@ PHPAPI int php_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, stru
6161
FD_ZERO(&sock_except);
6262

6363
/* build an array of handles for non-sockets */
64-
for (i = 0; i < max_fd; i++) {
64+
for (i = 0; i < INT_MAX && i < max_fd; i++) {
6565
if (SAFE_FD_ISSET(i, rfds) || SAFE_FD_ISSET(i, wfds) || SAFE_FD_ISSET(i, efds)) {
6666
handles[n_handles] = (HANDLE)(zend_uintptr_t)_get_osfhandle(i);
6767
if (handles[n_handles] == INVALID_HANDLE_VALUE) {
@@ -87,7 +87,7 @@ PHPAPI int php_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, stru
8787

8888
if (n_handles == 0) {
8989
/* plain sockets only - let winsock handle the whole thing */
90-
return select(max_fd, rfds, wfds, efds, tv);
90+
return select(0, rfds, wfds, efds, tv);
9191
}
9292

9393
/* mixture of handles and sockets; lets multiplex between
@@ -111,7 +111,7 @@ PHPAPI int php_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, stru
111111
tvslice.tv_sec = 0;
112112
tvslice.tv_usec = 100000;
113113

114-
retcode = select(sock_max_fd+1, &aread, &awrite, &aexcept, &tvslice);
114+
retcode = select(0, &aread, &awrite, &aexcept, &tvslice);
115115
}
116116
if (n_handles > 0) {
117117
/* check handles */

win32/select.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818

1919
/* $Id$ */
2020

21-
PHPAPI int php_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv);
21+
#include "php_network.h"
2222

23+
PHPAPI int php_select(php_socket_t max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv);

0 commit comments

Comments
 (0)