[php-src] master: Merge branch 'PHP-8.6'
| From: | Jakub Zelenka | Date: | Sun, 01 Nov 2026 21:10:40 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143196@lists.php.net to get a copy of this message | ||
Author: Jakub Zelenka (bukka)
Date: 2026-11-01T22:10:32+01:00
Commit: https://github.com/php/php-src/commit/39a57ce52fe7bfe2380d965d1c5ffb1f60f37547
Raw diff: https://github.com/php/php-src/commit/39a57ce52fe7bfe2380d965d1c5ffb1f60f37547.diff
Merge branch 'PHP-8.6'
* PHP-8.6:
Fix the WSAPoll backend of Io\Poll accepting handles that are not sockets
Changed paths:
A ext/standard/tests/poll/poll_stream_add_unpollable_wsapoll.phpt
M main/poll/poll_backend_wsapoll.c
Diff:
diff --git a/ext/standard/tests/poll/poll_stream_add_unpollable_wsapoll.phpt
b/ext/standard/tests/poll/poll_stream_add_unpollable_wsapoll.phpt
new file mode 100644
index 000000000000..ac4d2f89ac22
--- /dev/null
+++ b/ext/standard/tests/poll/poll_stream_add_unpollable_wsapoll.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Io\Poll: WSAPoll reports a handle that is not a socket as unsupported
+--SKIPIF--
+<?php
+if (!Io\Poll\Backend::WSAPoll->isAvailable()) {
+ die("skip WSAPoll backend required\n");
+}
+if (!function_exists('proc_open')) {
+ die("skip proc_open required\n");
+}
+?>
+--FILE--
+<?php
+require_once __DIR__ . '/poll.inc';
+
+$ctx = new Io\Poll\Context(Io\Poll\Backend::WSAPoll);
+
+// WSAPoll() only polls sockets, while files and pipes give a CRT fd
+$proc = proc_open([PHP_BINARY, '-n', '-r', 'echo "done";'],
[1 => ['pipe', 'w']], $pipes);
+foreach (['regular file' => fopen(__FILE__, 'r'), 'pipe' =>
$pipes[1]] as $label => $stream) {
+ try {
+ $ctx->add(new StreamPollHandle($stream), [Io\Poll\Event::Read]);
+ echo "$label: added\n";
+ } catch (Io\Poll\FailedHandleAddException $e) {
+ printf("%s: %s, code %s\n", $label, $e->getMessage(),
+ Io\Poll\FailedPollOperationException::ERROR_NOSUPPORT === $e->getCode() ?
'ERROR_NOSUPPORT' : $e->getCode());
+ }
+ fclose($stream);
+}
+proc_close($proc);
+
+// a socket is still added and reported
+[$r, $w] = pt_new_socket_pair();
+$watcher = $ctx->add(new StreamPollHandle($r), [Io\Poll\Event::Read]);
+echo "socket: added\n";
+fwrite($w, "ping");
+$events = $ctx->wait(Time\Duration::fromSeconds(5));
+var_dump(count($events), $events[0] === $watcher);
+?>
+--EXPECT--
+regular file: Failed to add handle, code ERROR_NOSUPPORT
+pipe: Failed to add handle, code ERROR_NOSUPPORT
+socket: added
+int(1)
+bool(true)
diff --git a/main/poll/poll_backend_wsapoll.c b/main/poll/poll_backend_wsapoll.c
index 101a7cfe0e4b..c89a02bfdd24 100644
--- a/main/poll/poll_backend_wsapoll.c
+++ b/main/poll/poll_backend_wsapoll.c
@@ -120,6 +120,15 @@ static zend_result wsapoll_backend_add(php_poll_ctx *ctx, int fd, uint32_t
event
return FAILURE;
}
+ /* WSAPoll() can only poll sockets, so reject files and pipes. */
+ int type;
+ int type_len = sizeof(type);
+ if (getsockopt((SOCKET) fd, SOL_SOCKET, SO_TYPE, (char *) &type, &type_len) != 0
+ && WSAGetLastError() == WSAENOTSOCK) {
+ php_poll_set_error(ctx, PHP_POLL_ERR_NOSUPPORT);
+ return FAILURE;
+ }
+
php_poll_fd_entry *entry = php_poll_fd_table_get_new(backend_data->fd_table, fd);
if (!entry) {
php_poll_set_error(ctx, PHP_POLL_ERR_NOMEM);