Skip to content

ssh2_poll resource check#96

Merged
rlerdorf merged 1 commit intomasterfrom
fix/ssh2-poll-resource-check
Apr 4, 2026
Merged

ssh2_poll resource check#96
rlerdorf merged 1 commit intomasterfrom
fix/ssh2-poll-resource-check

Conversation

@rlerdorf
Copy link
Copy Markdown
Member

@rlerdorf rlerdorf commented Apr 4, 2026

Fix ssh2_poll() rejecting valid resource inputs

Fixes #82

Problem

ssh2_poll() always fails with:

PHP Warning: ssh2_poll(): Invalid data in subarray, no resource element, or not of type resource

The resource check on the input array requires the resource value to be an IS_REFERENCE wrapping an IS_RESOURCE. When the array is constructed normally in PHP, the value is just IS_RESOURCE directly, so the check always fails.

Fix

Use ZVAL_DEREF() to unwrap references when present, then check for IS_RESOURCE. This handles both direct resources and reference-wrapped resources, rather than requiring one or the other.

PR #82 proposed dropping the reference handling entirely. That works for the common case but would break if the value happens to be a reference (e.g. array modified by-ref elsewhere). ZVAL_DEREF is the standard PHP engine pattern for this.

Test

Added tests/ssh2_poll.phpt which passes a direct (non-reference) stream resource to ssh2_poll() and verifies it returns successfully with revents populated.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes ssh2_poll() incorrectly rejecting valid input arrays by properly handling both direct resources and reference-wrapped resources, and adds a regression test to ensure polling works with a normal (non-reference) stream resource.

Changes:

  • Update ssh2_poll() to ZVAL_DEREF() the resource element before validating it is an IS_RESOURCE.
  • Add a new PHPT test that passes a direct ssh2_exec() stream resource to ssh2_poll() and asserts revents is populated.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
ssh2.c Fixes resource type validation in ssh2_poll() to accept typical PHP array values (direct IS_RESOURCE) as well as references.
tests/ssh2_poll.phpt Adds regression coverage ensuring ssh2_poll() succeeds and populates revents for a direct stream resource.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rlerdorf rlerdorf merged commit 695ba89 into master Apr 4, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants