From:             axelluttgens at swing dot be
Operating system: Mac OS X 10.4.7
PHP version:      4.4.2
PHP Bug Type:     Sockets related
Bug description:  socket_select() and invalid arguments

Description:
------------
socket_select(), when executed without timeout, is liable to block
indefinitely in case of obviously incorrect arguments.

I may be wrong, but this doesn't seem to exactly reflect the behavior of
select(2).
In which case the PHP layer might be too permissive while building the
descriptors from the arguments passed to socket_select(); perhaps by
building valid descriptors when it shouldn't be the case.




Reproduce code:
---------------
Create an executable file (say, test.php) with following contents:

#!/usr/local/bin/php
<?php

while (!$cnt = socket_select($r = array('xyzt'), $w = NULL, $e = NULL,
1))
{
        echo "Count: $cnt\n";
        echo "Err#: ", socket_last_error(), "\n";
}

?>




Expected result:
----------------
socket_select() should exit immediately with an error code reported
through socket_last_error() (for example SOCKET_EBADF).




Actual result:
--------------
[1] When running above executable, a warning gets emitted on stdout:

    Warning: socket_select(): supplied argument is not a
    valid Socket resource in /path/to/test.php on line 4

    ^C

but execution indefinitely continues in socket_select(): the loop's body
is never executed, and one has to interrupt the program (hence the ^C).

[2] Note that the behavior differs with
    $r = 'xyzt';
instead of:
    $r = array('xyzt');
socket_select() then exits, allowing to enter the loop's body; the output
is:

    Warning: socket_select() expects parameter 1 to be
    array, string given in /path/to/test.php on line 4
    Count: 
    Err#: 0

    Warning: socket_select() expects parameter 1 to be
    array, string given in /path/to/test.php on line 4
    Count: 
    Err#: 0

    ^C

Here, PHP quits socket_select() and reports an error (at least through the
value FALSE asigned to $cnt).

[3] Now, with
    $r = array('xyzt')
again, but changing the timeout value from NULL to 1, the output is:

    Warning: socket_select(): supplied argument is not a
    valid Socket resource in /path/to/test.php on line 5

    Warning: socket_select(): supplied argument is not a
    valid Socket resource in /path/to/test.php on line 5
    Count: 0
    Err#: 0

    Warning: socket_select(): supplied argument is not a
    valid Socket resource in /path/to/test.php on line 5
    Count: 0
    Err#: 0
    ^C

Strange... why does the warning get emitted twice at the beginning of the
execution?

======
Additional info:

Configure Command =>  './configure' '--prefix=/usr/local' '--with-apxs'
'--disable-dependency-tracking' '--with-ldap=/usr' '--with-kerberos=/usr'
'--enable-cli' '--with-zlib-dir=/usr' '--enable-trans-sid' '--with-xml'
'--enable-exif' '--enable-ftp' '--enable-mbstring' '--enable-mbregex'
'--enable-dbx' '--enable-sockets' '--with-iodbc=/usr' '--with-curl=/usr'
'--with-mysql' '--enable-dba' '--with-db4=/usr/local/BerkeleyDB'
'--enable-pcntl'




-- 
Edit bug report at http://bugs.php.net/?id=38251&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=38251&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=38251&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=38251&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=38251&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=38251&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=38251&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=38251&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=38251&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=38251&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=38251&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=38251&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=38251&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=38251&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=38251&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=38251&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=38251&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=38251&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=38251&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=38251&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=38251&r=mysqlcfg

Reply via email to