Skip to content

Fix socket_sendmsg() sending wrong fd for Socket objects in SCM_RIGHTS#87

Closed
iliaal wants to merge 2 commits into
PHP-8.4from
fix-scm-rights-fd
Closed

Fix socket_sendmsg() sending wrong fd for Socket objects in SCM_RIGHTS#87
iliaal wants to merge 2 commits into
PHP-8.4from
fix-scm-rights-fd

Conversation

@iliaal

@iliaal iliaal commented Jun 16, 2026

Copy link
Copy Markdown
Owner

socket_sendmsg() sends the wrong file descriptors when a Socket object is passed in an SCM_RIGHTS control message: the object branch of from_zval_write_fd_array_aux() indexes the fd array with the 1-based loop counter (iarr[i]) instead of iarr[i - 1] like the resource branch, so slot 0 stays zeroed and a single Socket object delivers fd 0 (stdin) to the receiver instead of the socket. Broken since the 8.0 resource-to-object conversion.

The existing socket_cmsg_rights.phpt only asserted is_resource() on the received descriptors, which masked this (the lost socket fd was replaced by stdin, still a stream); it now also accepts Socket objects.

@iliaal iliaal force-pushed the fix-scm-rights-fd branch from 66c8680 to 3da545b Compare June 16, 2026 20:00
@iliaal iliaal force-pushed the fix-scm-rights-fd branch from 3da545b to 9567392 Compare June 16, 2026 21:14
from_array_iterate() yields a 1-based index. The Socket-object branch of
from_zval_write_fd_array_aux() wrote iarr[i] while the resource branch
correctly used iarr[i - 1], so the first descriptor slot was left zeroed
and every object descriptor was shifted up by one, with the last
truncated by cmsg_len. socket_sendmsg() therefore transmitted the wrong
descriptors (the first always fd 0) whenever a Socket object was passed
in an SCM_RIGHTS control message.

Closes phpGH-22338
@iliaal

iliaal commented Jun 16, 2026

Copy link
Copy Markdown
Owner Author

Submitted upstream as php#22338.

@iliaal iliaal force-pushed the fix-scm-rights-fd branch from 9567392 to fca8166 Compare June 16, 2026 21:15
@iliaal iliaal closed this Jun 16, 2026
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