From: pz4u at vplace dot de Operating system: Linux PHP version: 5.2.5 PHP Bug Type: Sockets related Bug description: UNIX abstract namespace socket connects only work sometimes
Description: ------------ I'm currently developing a binding for D-BUS based on native PHP. For that reason I need to talk to abstract namespace sockets. It seems like PHP is handling these socket type differently than D-BUS. I can't connect to the abstract socket. I asked for help on the php-general mailing list and got some helpful responses for further investigation: http://marc.info/?t=120291320800005&r=1&w=2 After that I asked on the D-BUS mailing list for clarification how D-BUS implements abstract namespace support: http://lists.freedesktop.org/archives/dbus/2008-February/009303.html As pointed out by Havoc on the dbus mailing list I think the problem is here: http://cvs.php.net/viewvc.cgi/php-src/ext/sockets/sockets.c?revision=1.197&view=markup or in the stream version of this API (not sure if it uses the same functions). - I'm wondering why 108 is hardcoded here (in the connect function). A constant might be better? - "If the connect() or listen() just does sizeof(struct sockaddr_un) then it will always get a bunch of trailing garbage bytes in the abstract name." (quoted Havoc here) - Even if their is no NUL byte to mark the end of the string PHP should only use non-nul byte characters for the path (or better: the string that has been given by the programmer.) If a programmer want's to fill up sun_path with NUL bytes, it should be added to the PHP code and not "assumed". I'm not a C programmer - so the code in sockets.c might just do what I wrote - I'm sorry for any inconveniences in this case. This seems to be a regression of bug #16121 Reproduce code: --------------- <?php // use env to find a current abstract D-BUS socket $fp = fsockopen ("unix://\x00/tmp/dbus-whatever",0); if ($fp) { fclose ($fp); } ?> Expected result: ---------------- A connect with \x00/tmp/dbus-whatever (without added NUL bytes until the maximum sun path length is reached). Actual result: -------------- fsockopen: fsockopen(): unable to connect to unix://:0 (Connection refused) for unix://\x00/tmp/dbus-whatever which is a bit strange because I expected at least the error message "fsockopen() [function.fsockopen]: unable to connect to unix://[NUL byte]/tmp/dbus-whatever:0 (Connection refused)" stream_socket_client: stream_socket_client: unable to connect to unix://\0/tmp/hald-local/dbus-ZniNmvr5O0 (Connection refused) in ... socket_connect: Warning: socket_connect(): unable to connect [22]: Invalid argument in ... I can garantuee that the arguments are right - removing the NUL byte from socket_connect allows me to connect to a non-abstract socket. -- Edit bug report at http://bugs.php.net/?id=44127&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=44127&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44127&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44127&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44127&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=44127&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=44127&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=44127&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=44127&r=needscript Try newer version: http://bugs.php.net/fix.php?id=44127&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=44127&r=support Expected behavior: http://bugs.php.net/fix.php?id=44127&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=44127&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=44127&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=44127&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=44127&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=44127&r=dst IIS Stability: http://bugs.php.net/fix.php?id=44127&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=44127&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=44127&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=44127&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=44127&r=mysqlcfg