com php-src: Fixed php_socket_t to int conversion: sapi/cli/php_cli.c win32/select.c win32/se lect.h
| From: | Anatol Belski | Date: | Thu, 15 Jun 2017 21:48:03 +0000 |
| Subject: | com php-src: Fixed php_socket_t to int conversion: sapi/cli/php_cli.c win32/select.c win32/se lect.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-98082@lists.php.net to get a copy of this message | ||
Commit: 5fa1cd224b3801a99790f367feca4d98b53771b7
Author: Richard Fussenegger <fleshgrinder@users.noreply.github.com> Mon, 29 May
2017 21:42:59 +0200
Committer: Anatol Belski <ab@php.net> Thu, 15 Jun 2017 23:48:03 +0200
Parents: fb6e718764fa33f0f4461c485cd12b89613db9c6
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=5fa1cd224b3801a99790f367feca4d98b53771b7
Log:
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 bf64fd5984409a208ef32108990a6085b6556273.
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
Changed paths:
M sapi/cli/php_cli.c
M win32/select.c
M win32/select.h
Diff:
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c
index 0ff8b41..07e8a8c 100644
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@ -248,7 +248,7 @@ static void print_extensions(void) /* {{{ */
#define STDERR_FILENO 2
#endif
-static inline int sapi_cli_select(int fd)
+static inline int sapi_cli_select(php_socket_t fd)
{
fd_set wfd, dfd;
struct timeval tv;
diff --git a/win32/select.c b/win32/select.c
index 7060ebf..c59e4ba 100644
--- a/win32/select.c
+++ b/win32/select.c
@@ -34,7 +34,7 @@
* - Calling this with NULL sets as a portable way to sleep with sub-second
* accuracy is not supported.
* */
-PHPAPI int php_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv)
+PHPAPI int php_select(php_socket_t max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval
*tv)
{
ULONGLONG ms_total, limit;
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
FD_ZERO(&sock_except);
/* build an array of handles for non-sockets */
- for (i = 0; i < max_fd; i++) {
+ for (i = 0; i < INT_MAX && i < max_fd; i++) {
if (SAFE_FD_ISSET(i, rfds) || SAFE_FD_ISSET(i, wfds) || SAFE_FD_ISSET(i, efds)) {
handles[n_handles] = (HANDLE)(zend_uintptr_t)_get_osfhandle(i);
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
if (n_handles == 0) {
/* plain sockets only - let winsock handle the whole thing */
- return select(max_fd, rfds, wfds, efds, tv);
+ return select(0, rfds, wfds, efds, tv);
}
/* 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
tvslice.tv_sec = 0;
tvslice.tv_usec = 100000;
- retcode = select(sock_max_fd+1, &aread, &awrite, &aexcept, &tvslice);
+ retcode = select(0, &aread, &awrite, &aexcept, &tvslice);
}
if (n_handles > 0) {
/* check handles */
diff --git a/win32/select.h b/win32/select.h
index 6f2d12e..ef91684 100644
--- a/win32/select.h
+++ b/win32/select.h
@@ -18,5 +18,6 @@
/* $Id$ */
-PHPAPI int php_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv);
+#include "php_network.h"
+PHPAPI int php_select(php_socket_t max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval
*tv);