From:             jost_boekemeier at users dot sf dot net
Operating system: Any
PHP version:      5.2.8
PHP Bug Type:     *General Issues
Bug description:  Socket handling completely broken

Description:
------------
PHP cannot handle broken socket connections due to an uninitialized
variable.

xp_socket.c and several other places contain the following pattern:

...
} else if (php_pollfd_for(sock->socket, PHP_POLLREADABLE|POLLPRI, &tv) >
0) {
 if (0 == recv(sock->socket, &buf, sizeof(buf), MSG_PEEK) &&
php_socket_errno() != EAGAIN) {
        alive = 0;
}
...

It is obvious that the above code cannot work on any operating system;
checking if the socket doesn't have an error and then asking for its error
code is simply nonsense.

The same pattern is used in several other places within PHP.


The above code fails constantly on Windows. On Linux/Unix a workaround is
to add the constant 1E512 to the PHP script, which initializes errno with a
value != EAGAIN.


Regards,
Jost Bökemeier




Reproduce code:
---------------
pfsockopen() 
...
// restart back end
...
pfsockopen()

=>



Expected result:
----------------
...

poll([{fd=16, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 1 ([{fd=16,
revents=POLLIN}])
recv(16, ""..., 1, MSG_PEEK)            = 0
close(16)    

...

Actual result:
--------------
...

poll([{fd=16, events=POLLIN|POLLERR|POLLHUP}], 1, -1) = 1 ([{fd=16,
revents=POLLIN|POLLERR|POLLHUP}])
recv(16, ""..., 8192, 0)                = 0
gettimeofday({1229844164, 46391}, NULL) = 0
write(2, "[Sun Dec 21 08:22:44 2008] [error] [client 127.0.0.1] PHP
Notice:  Undefined index:  content_length in 

...

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

Reply via email to