[PECL-CVS] [pecl-networking-ssh2] fix/ssh2-poll-resource-check: ssh2_poll resource check

[email protected] (Rasmus Lerdorf) Sat, 4 Apr 2026 11:45:37 +0000
Newsgroups php.pecl.cvs
Message-ID <[email protected]>
Author: Rasmus Lerdorf (rlerdorf)
Date: 2026-04-04T07:45:21-04:00

Commit: https://github.com/php/pecl-networking-ssh2/commit/69f945d884a376eec0ace12b4ee4f5f0c8af157f
Raw diff: https://github.com/php/pecl-networking-ssh2/commit/69f945d884a376eec0ace12b4ee4f5f0c8af157f.diff

ssh2_poll resource check

Changed paths:
  A  tests/ssh2_poll.phpt
  M  ssh2.c


Diff:

diff --git a/ssh2.c b/ssh2.c
index 8bd51cb..afd29b9 100644
--- a/ssh2.c
+++ b/ssh2.c
@@ -992,8 +992,14 @@ PHP_FUNCTION(ssh2_poll)
 
 		pollfds[i].events = Z_LVAL_P(tmpzval);
 		hash_key_zstring = zend_string_init("resource", sizeof("resource") - 1, 0);
-		if ((tmpzval = zend_hash_find(Z_ARRVAL_P(subarray), hash_key_zstring)) == NULL || Z_TYPE_P(tmpzval) != IS_REFERENCE
-			|| (tmpzval = Z_REFVAL_P(tmpzval)) == NULL || Z_TYPE_P(tmpzval) != IS_RESOURCE) {
+		if ((tmpzval = zend_hash_find(Z_ARRVAL_P(subarray), hash_key_zstring)) == NULL) {
+			php_error_docref(NULL, E_WARNING, "Invalid data in subarray, no resource element, or not of type resource");
+			numfds--;
+			zend_string_release(hash_key_zstring);
+			continue;
+		}
+		ZVAL_DEREF(tmpzval);
+		if (Z_TYPE_P(tmpzval) != IS_RESOURCE) {
 			php_error_docref(NULL, E_WARNING, "Invalid data in subarray, no resource element, or not of type resource");
 			numfds--;
 			zend_string_release(hash_key_zstring);
diff --git a/tests/ssh2_poll.phpt b/tests/ssh2_poll.phpt
new file mode 100644
index 0000000..fd9b9f1
--- /dev/null
+++ b/tests/ssh2_poll.phpt
@@ -0,0 +1,34 @@
+--TEST--
+ssh2_poll() - Tests polling a channel for events
+--SKIPIF--
+<?php require('ssh2_skip.inc'); ssh2t_needs_auth(); ?>
+--FILE--
+<?php require('ssh2_test.inc');
+
+$ssh = ssh2_connect(TEST_SSH2_HOSTNAME, TEST_SSH2_PORT);
+ssh2t_auth($ssh);
+
+$stream = ssh2_exec($ssh, 'echo "poll test"');
+stream_set_blocking($stream, false);
+
+echo "**Poll with direct resource\n";
+$polldesc = array(
+    array(
+        'resource' => $stream,
+        'events' => SSH2_POLLIN,
+    ),
+);
+$ready = ssh2_poll($polldesc, 5);
+var_dump(is_int($ready));
+var_dump($ready >= 0);
+
+echo "**Poll result has revents\n";
+var_dump(array_key_exists('revents', $polldesc[0]));
+
+fclose($stream);
+--EXPECT--
+**Poll with direct resource
+bool(true)
+bool(true)
+**Poll result has revents
+bool(true)