Skip to content

Commit 94625a0

Browse files
dktappsndossche
authored andcommitted
Fix phpGH-19722: Windows: _get_osfhandle asserts in debug mode when given a socket
Closes phpGH-19725.
1 parent 472f2fe commit 94625a0

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ PHP NEWS
6161
. Fix arginfo/zpp violations when LIBXML_SCHEMAS_ENABLED is not available.
6262
(nielsdos)
6363

64+
- Windows:
65+
. Fix GH-19722 (_get_osfhandle asserts in debug mode when given a socket).
66+
(dktapps)
67+
6468
23 Oct 2025, PHP 8.3.27
6569

6670
- Core:

win32/select.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ PHPAPI int php_select(php_socket_t max_fd, fd_set *rfds, fd_set *wfds, fd_set *e
6262
/* build an array of handles for non-sockets */
6363
for (i = 0; (uint32_t)i < max_fd; i++) {
6464
if (SAFE_FD_ISSET(i, rfds) || SAFE_FD_ISSET(i, wfds) || SAFE_FD_ISSET(i, efds)) {
65-
handles[n_handles] = (HANDLE)(uintptr_t)_get_osfhandle(i);
66-
if (handles[n_handles] == INVALID_HANDLE_VALUE) {
65+
int _type;
66+
int _len = sizeof(_type);
67+
68+
if (getsockopt((SOCKET)i, SOL_SOCKET, SO_TYPE, (char*)&_type, &_len) == 0 || WSAGetLastError() != WSAENOTSOCK) {
6769
/* socket */
6870
if (SAFE_FD_ISSET(i, rfds)) {
6971
FD_SET((uint32_t)i, &sock_read);
@@ -78,8 +80,11 @@ PHPAPI int php_select(php_socket_t max_fd, fd_set *rfds, fd_set *wfds, fd_set *e
7880
sock_max_fd = i;
7981
}
8082
} else {
81-
handle_slot_to_fd[n_handles] = i;
82-
n_handles++;
83+
handles[n_handles] = (HANDLE)(uintptr_t)_get_osfhandle(i);
84+
if (handles[n_handles] != INVALID_HANDLE_VALUE) {
85+
handle_slot_to_fd[n_handles] = i;
86+
n_handles++;
87+
}
8388
}
8489
}
8590
}

0 commit comments

Comments
 (0)