php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28996 fsockopen(unix_socket) and file descriptors leaking
Submitted: 2004-07-02 18:30 UTC Modified: 2004-07-02 19:27 UTC
From: b dot mourgues at newtech dot fr Assigned:
Status: Closed Package: Sockets related
PHP Version: 4CVS-2004-07-02 (stable) OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
34 - 21 = ?
Subscribe to this entry?

 
 [2004-07-02 18:30 UTC] b dot mourgues at newtech dot fr
Description:
------------
When using fsockopen with non "available" unix socket, fsockopen returns FALSE (no file descriptor), but an unix socket remains opened in webserver process running php.

run
watch -n 1 'lsof -U | grep ^apache | wc -l'

while opening the following page (replacing "apache" by the real name of your webserver).

Suggestion : in file main/network.c, in function _php_stream_sock_open_unix, when php_connect_nonb fails, closesocket(socketd) should be invoked before returning NULL.

Reproduce code:
---------------
<?php
        $PHPfd = fsockopen("/dev/null", 0, $PHPerrno, $PHPerrstr);
        if($PHPfd)
        {
                fclose($PHPfd);
        }
?>

<html><head><title>fsockopen</title></head>
<body>
<pre>
PID : <?php print getmypid() . " ".  $PHPerrstr . "."; ?>
</pre>
</body></html>


Expected result:
----------------
When fsockopen returns FALSE, no file descriptor created by this function should remain opened


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-02 19:27 UTC] wez@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

The next snapshot from snaps.php.net will contain the fix.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Oct 07 06:05:54 2022 UTC