php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8761 read() on udp-sockets fails
Submitted: 2001-01-17 10:28 UTC Modified: 2001-06-02 21:08 UTC
From: mavetju at chello dot nl Assigned:
Status: Closed Package: Sockets related
PHP Version: 4.0.4 OS: FreeBSD 4.0
Private report: No CVE-ID: None
 [2001-01-17 10:28 UTC] mavetju at chello dot nl
<?
    $port=7;
    $ip="127.0.0.1";
    $sock=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
    $retval=connect($sock,$ip,$port);

    write($sock,"blaat\n",6);

    $numread=read($sock,&$readdata,1);
    printf("%d %02x %s\n",$numread,ord($readdata),$readdata);

    close($sock);
?>

When changing the 1 on read() to a different number, or when calling it multiple times, the read() function hangs due to an unknown reason (at least for me). This example tries to read from the echo-service, I encountered the problem when developing a radius-client in PHP.

This is the stack of the process:
#0  0x2825b794 in read () from /usr/lib/libc.so.4
#1  0x809dd78 in php_read (fd=4, buf=0x81e512c, maxlen=2) at sockets.c:640
#2  0x809df38 in php_if_read (ht=3, return_value=0x821768c, this_ptr=0x0,
    return_value_used=1) at sockets.c:692
#3  0x81121bc in execute (op_array=0x820948c) at ./zend_execute.c:1519
#4  0x80ea45b in zend_execute_scripts (type=8, file_count=3) at zend.c:729
#5  0x807c360 in php_execute_script (primary_file=0xbfbff408) at main.c:1221
#6  0x80f5eda in apache_php_module_main (r=0x821b034, display_source_mode=0)
    at sapi_apache.c:89
#7  0x8079cda in send_php ()
#8  0x8079d12 in send_parsed_php ()
#9  0x811c7f5 in ap_invoke_handler ()
#10 0x8130850 in process_request_internal ()
#11 0x81308ba in ap_process_request ()
#12 0x8127b2b in child_main ()
#13 0x8127db0 in make_child ()
#14 0x8128134 in perform_idle_server_maintenance ()
#15 0x8128659 in standalone_main ()
#16 0x8128c88 in main ()
#17 0x8062801 in _start ()

and info on the first two frames:
(gdb) up
#1  0x809dd78 in php_read (fd=4, buf=0x81e512c, maxlen=2) at sockets.c:640
640                       m = read(fd, (void *) t, 1);

(gdb) info locals
t = 0x81e512d "laat"
m = 1
n = 1
no_read = 1
nonblock = 0

(gdb) up
#2  0x809df38 in php_if_read (ht=3, return_value=0x821768c, this_ptr=0x0,
    return_value_used=1) at sockets.c:692

(gdb) info locals
ht = 136204588
return_value = (zval *) 0x821768c
fd = (zval **) 0x8216c0c
buf = (zval **) 0x8216c10
length = (zval **) 0x8216c14
binary = (zval **) 0x78b740
tmpbuf = 0x81e512c "blaat"
ret = 134864068
read_function = (int (*)()) 0x809dcc4 <php_read>
 
configure is ran with:
Configure Command './configure' '--with-apache=../apache_1.3.12' '--enable-track-vars' '--with-ndbm' '--with-db' '--with-mysql' '--enable-sockets'

If you need more information, feel free to ask me.

Edwin

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-02 21:08 UTC] sniper@php.net
Please try the latest release candidate:

http://www.php.net/~andi/php-4.0.6RC2.tar.gz

And note that using the undocumented 4th parameter
will make it behave like the system read():

read($sock, $buff, $length, PHP_BINARY_READ)

-Jani

 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Apr 10 19:01:24 2020 UTC