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.

@iliaal iliaal requested a review from devnexen as a code owner June 16, 2026 21:14
iliaal added a commit to iliaal/php-src that referenced this pull request Jun 16, 2026
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 force-pushed the fix-scm-rights-fd branch from 9567392 to fca8166 Compare June 16, 2026 21:15
@devnexen

Copy link
Copy Markdown
Member

fix itself lgtm, one suggestion for the test, send 1/2 fds in a single SCM_RIGHTS message.

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 force-pushed the fix-scm-rights-fd branch from fca8166 to 6da341f Compare June 19, 2026 20:44
@iliaal

iliaal commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

@devnexen Done.

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.

2 participants