Conversation
There was a problem hiding this comment.
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()toZVAL_DEREF()theresourceelement before validating it is anIS_RESOURCE. - Add a new PHPT test that passes a direct
ssh2_exec()stream resource tossh2_poll()and assertsreventsis 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix ssh2_poll() rejecting valid resource inputs
Fixes #82
Problem
ssh2_poll()always fails with:The resource check on the input array requires the
resourcevalue to be anIS_REFERENCEwrapping anIS_RESOURCE. When the array is constructed normally in PHP, the value is justIS_RESOURCEdirectly, so the check always fails.Fix
Use
ZVAL_DEREF()to unwrap references when present, then check forIS_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_DEREFis the standard PHP engine pattern for this.Test
Added
tests/ssh2_poll.phptwhich passes a direct (non-reference) stream resource tossh2_poll()and verifies it returns successfully withreventspopulated.