Skip to content

Commit 36057b9

Browse files
dktappsnielsdos
authored andcommitted
Fix GH-19722: Windows: _get_osfhandle asserts in debug mode when given a socket
Closes GH-19725.
1 parent 29c7ee4 commit 36057b9

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ PHP NEWS
1111
. Fixed bug GH-19780 (InvalidUrlException should check $errors argument).
1212
(nielsdos)
1313

14+
- Windows:
15+
. Fix GH-19722 (_get_osfhandle asserts in debug mode when given a socket).
16+
(dktapps)
17+
1418
11 Sep 2025, PHP 8.5.0beta3
1519

1620
- Core:

win32/select.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ PHPAPI int php_select(php_socket_t max_fd, fd_set *rfds, fd_set *wfds, fd_set *e
6666
/* build an array of handles for non-sockets */
6767
for (i = 0; (uint32_t)i < max_fd; i++) {
6868
if (SAFE_FD_ISSET(i, rfds) || SAFE_FD_ISSET(i, wfds) || SAFE_FD_ISSET(i, efds)) {
69-
handles[n_handles] = (HANDLE)(uintptr_t)_get_osfhandle(i);
70-
if (handles[n_handles] == INVALID_HANDLE_VALUE) {
69+
int _type;
70+
int _len = sizeof(_type);
71+
72+
if (getsockopt((SOCKET)i, SOL_SOCKET, SO_TYPE, (char*)&_type, &_len) == 0 || WSAGetLastError() != WSAENOTSOCK) {
7173
/* socket */
7274
if (SAFE_FD_ISSET(i, rfds)) {
7375
FD_SET((uint32_t)i, &sock_read);
@@ -82,11 +84,14 @@ PHPAPI int php_select(php_socket_t max_fd, fd_set *rfds, fd_set *wfds, fd_set *e
8284
sock_max_fd = i;
8385
}
8486
} else {
85-
if (SAFE_FD_ISSET(i, rfds) && GetFileType(handles[n_handles]) == FILE_TYPE_PIPE) {
86-
num_read_pipes++;
87+
handles[n_handles] = (HANDLE)(uintptr_t)_get_osfhandle(i);
88+
if (handles[n_handles] != INVALID_HANDLE_VALUE) {
89+
if (SAFE_FD_ISSET(i, rfds) && GetFileType(handles[n_handles]) == FILE_TYPE_PIPE) {
90+
num_read_pipes++;
91+
}
92+
handle_slot_to_fd[n_handles] = i;
93+
n_handles++;
8794
}
88-
handle_slot_to_fd[n_handles] = i;
89-
n_handles++;
9095
}
9196
}
9297
}

0 commit comments

Comments
 (0)