|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21829 fsockopen() crashes on 2 of 3 servers (w/ gdb trace)
Submitted: 2003-01-22 19:42 UTC Modified: 2003-02-07 23:46 UTC
From: michael at fni dot com Assigned:
Status: No Feedback Package: Sockets related
PHP Version: 4.3.0 OS: mandrake 8.2, 2.4.18-8.1mdk
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: michael at fni dot com
New email:
PHP Version: OS:


 [2003-01-22 19:42 UTC] michael at fni dot com
Compiling 4.3.0 and php4-STABLE-200301222030 on 3 servers, one works and two segfault.  The simple script below illustrates the problem; on one server it runs, on two it faults.  The three servers are essentially identical; php.ini on all are identical.

Build details and gdb backtrace are below.  I also have fopen("http://") failing the same way, not surprising.  The failure appears to be in DNS resolution.  Glad to supply more info as needed.

$fd = fsockopen("", 80, &$errno, &$errstr);
if( !$fd ) {
    echo "yahoo not available";
} else {
    fputs($fd,"GET / HTTP/1.0\r\n\r\n");
    fputs($fd,"Host: $host\r\n\r\n");
    while (!feof($fd)) {
        echo fread($fd,16000);


php was built with the following options:

./configure \
 --with-gd \
 --with-mysql=/usr \
 --with-exec-dir=/var/lib/php \
 --with-java=/usr/local/jdk \
 --enable-unified-odbc \
 --enable-safe-mode=yes \
 --enable-track-vars \
 --enable-ftp \
 --with-expat-dir=/usr \
 --with-xml \
 --with-dom=/usr \
 --with-dom-xslt=/usr \
 --with-dom-exslt=/usr \
 --enable-xslt \
 --with-xslt-sablot=/usr \
 --with-sablot-js=/usr \
 --with-zlib \
 --with-ldap \
 --with-openssl \
 --disable-debug \
 --disable-debugger \

The bind version on all servers is 8.3.3, patched with ISC patches prior to 8.3.4 release from recent bugs.


gdb run commands:

gdb stacktrace:(gdb) set args fsock_yahoo.php
(gdb) run
Starting program: /usr/local/bin/php fsock_yahoo.php
[New Thread 1024 (LWP 3639)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1024 (LWP 3639)]
0x081335d5 in php_network_getaddresses (host=0x831c59c "", 
    sal=0xbfffc634) at /usr/local/php4/main/network.c:215
215                                     *(struct sockaddr_in *)*sap =

#0  0x081335d5 in php_network_getaddresses (host=0x831c59c "", 
    sal=0xbfffc634) at /usr/local/php4/main/network.c:215
#1  0x08133810 in php_hostconnect (host=0x831c59c "", port=80, 
    socktype=1, timeout=0xbfffc6b0) at /usr/local/php4/main/network.c:410
#2  0x08133b5f in _php_stream_sock_open_host (host=0x831c59c "", 
    port=80, socktype=1, timeout=0xbfffc6b0, persistent_id=0x0)
    at /usr/local/php4/main/network.c:619
#3  0x080ee025 in php_fsockopen_stream (ht=4, return_value=0x831c5dc, 
    this_ptr=0x0, return_value_used=1, persistent=0)
    at /usr/local/php4/ext/standard/fsock.c:218
#4  0x080ee1ed in zif_fsockopen (ht=4, return_value=0x831c5dc, this_ptr=0x0, 
    return_value_used=1) at /usr/local/php4/ext/standard/fsock.c:278
#5  0x0815d2d2 in execute (op_array=0x8322504)
    at /usr/local/php4/Zend/zend_execute.c:1596
#6  0x0814cdf3 in zend_execute_scripts (type=8, retval=0x0, file_count=3)
    at /usr/local/php4/Zend/zend.c:864
#7  0x0812992b in php_execute_script (primary_file=0xbffff560)
    at /usr/local/php4/main/main.c:1573
#8  0x08164488 in main (argc=2, argv=0xbffff604)
    at /usr/local/php4/sapi/cli/php_cli.c:746
#9  0x405be280 in __libc_start_main () from /lib/


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-22 23:37 UTC] michael at fni dot com
I found the cause of this.  Somehow in my exported INCLUDE -I/usr/include had come before -I/usr/local/bind/include, and the DNS structures were taken from the wrong header files.  After setting the BIND include files to be searched first and recompiling, this appears to be resolved.
 [2003-01-23 03:52 UTC]
Please try using this CVS snapshot:
For Windows:

There were some fsockopen fixes recently; please try a snapshot.
 [2003-02-07 23:46 UTC]
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 17 17:01:29 2024 UTC