Skip to content

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

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix-scm-rights-fd
Open

Fix socket_sendmsg() sending wrong fd for Socket objects in SCM_RIGHTS#22338
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix-scm-rights-fd

Conversation

@iliaal

@iliaal iliaal commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

socket_sendmsg() transmits 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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant