From:             bugs dot php dot net at ss dot chernousov dot net
Operating system: Gentoo Linux
PHP version:      5.5.0
Package:          Sockets related
Bug Type:         Bug
Bug description:socket_sendmsg/socket_recvmsg wrong number of file descriptors

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 ) ... )

-- 
Edit bug report at https://bugs.php.net/bug.php?id=65260&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=65260&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=65260&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=65260&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=65260&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=65260&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=65260&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=65260&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=65260&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=65260&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=65260&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=65260&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=65260&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=65260&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65260&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=65260&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=65260&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=65260&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65260&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=65260&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=65260&r=mysqlcfg

Reply via email to