php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65260 socket_sendmsg/socket_recvmsg wrong number of file descriptors
Submitted: 2013-07-14 09:10 UTC Modified: 2013-07-15 06:30 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: bugs dot php dot net at ss dot chernousov dot net Assigned: cataphract (profile)
Status: Closed Package: Sockets related
PHP Version: 5.5.0 OS: Gentoo Linux
Private report: No CVE-ID: None
 [2013-07-14 09:10 UTC] bugs dot php dot net at ss dot chernousov dot net
Description:
------------
Regardless of how many file descriptors were sent with socket_sendmsg(), 
socket_recvmsg() always receives fd/0 as the very first descriptor (even if it 
wasn't sent at all) and then maximum two descriptors that were really sent.

Test script sends one descriptor $fd, but receives two, as described 
above. If we add more descriptors to send (let's say 5, and change third argument 
of socket_cmsg_space() to 5), only first two will be actually received, and extra 
fd/0 will precede them.

I know these functions are still experimental, but they are like a manna from 
heaven many backend php-developers were seeking.

Test script:
---------------
https://gist.github.com/5lava/5993637

Similar PHP test https://github.com/cataphract/php-src/blob/sendrecvmsg/ext/sockets/tests/socket_cmsg_rights.phpt taken from here: https://wiki.php.net/rfc/sendrecvmsg

Expected result:
----------------
One new file descriptors should be added after socket_recvmsg() call.

Actual result:
--------------
Two new file descriptors added.
First is always referencing fd/0, and 2nd is the one which was actually sent.

File descriptors before socket_recvmsg() call:

0 -> /etc/passwd <--- reopened fd/0
1 -> /dev/pts/3 <--- stdout
2 -> /dev/pts/3 <--- stderr
3 -> socket:[5819664] <--- $send_s
4 -> socket:[5819665] <--- $recv_s
5 -> /etc/group <--- $fd - the one we want to send
6 -> pipe:[5819666] <--- passthru() pipe

File descriptors after socket_recvmsg() call:

0 -> /etc/passwd <--- reopened fd/0
1 -> /dev/pts/3 <--- stdout
2 -> /dev/pts/3 <--- stderr
3 -> socket:[5819664] <--- $send_s
4 -> socket:[5819665] <--- $recv_s
5 -> /etc/group <--- $fd - the one we sent
6 -> /etc/passwd <--- always the same as fd/0 - shouldn't be here at all
7 -> /etc/group <--- that's the only one we expected to receive
6 -> pipe:[5819666] <--- passthru() pipe

$data contains two Resources:
Array ( ... [control] => [0] => [data] => Array (
                            [0] => Resource id #10
                            [1] => Resource id #11 ) ... )

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-14 23:54 UTC] cataphract@php.net
-Status: Open +Status: Feedback
 [2013-07-14 23:54 UTC] cataphract@php.net
Can you test this branch: https://github.com/cataphract/php-src/tree/bug65260 ?

Thanks
 [2013-07-14 23:56 UTC] cataphract@php.net
-Assigned To: +Assigned To: cataphract
 [2013-07-15 01:17 UTC] bugs dot php dot net at ss dot chernousov dot net
Works like a charm to me.
Thank you so much.
 [2013-07-15 06:30 UTC] cataphract@php.net
-Status: Feedback +Status: Assigned
 [2013-07-15 22:03 UTC] cataphract@php.net
Automatic comment on behalf of glopes@nebm.ist.utl.pt
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e2744f1aa33da3afade2c454b008c0de65a72da9
Log: socket: fix bug #65260 (SCM_RIGHTS)
 [2013-07-15 22:03 UTC] cataphract@php.net
-Status: Assigned +Status: Closed
 [2013-11-17 09:30 UTC] laruence@php.net
Automatic comment on behalf of glopes@nebm.ist.utl.pt
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e2744f1aa33da3afade2c454b008c0de65a72da9
Log: socket: fix bug #65260 (SCM_RIGHTS)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:29 2024 UTC