ID:               39396
 User updated by:  maurice at iceblog dot de
 Reported By:      maurice at iceblog dot de
 Status:           Open
 Bug Type:         Streams related
 Operating System: Windows XP
 PHP Version:      5.2.0
 New Comment:

stream_socket_client should at least return FALSE or an error if you
just use STREAM_CLIENT_ASYNC_CONNECT without STREAM_CLIENT_CONNECT.


Previous Comments:
------------------------------------------------------------------------

[2006-11-06 10:33:33] maurice at iceblog dot de

Description:
------------
When you use stream_socket_client with asynchronous connect
(STREAM_CLIENT_ASYNC_CONNECT), but do not specify STREAM_CLIENT_CONNECT
then stream_set_blocking will crash PHP on Windows XP.

The documentation does NOT tell you to use
STREAM_CLIENT_ASYNC_CONNECT | STREAM_CLIENT_CONNECT.

I think STREAM_CLIENT_ASYNC_CONNECT should implicate
STREAM_CLIENT_CONNECT.

-- Possibility 1 to fix implication ---------

#define STREAM_XPORT_CONNECT         2 
#define STREAM_XPORT_CONNECT_ASYNC   18  // instead of 16

#define PHP_STREAM_CLIENT_CONNECT        4
#define PHP_STREAM_CLIENT_ASYNC_CONNECT  6  // instead of 2
 
-- Possibility 2 to fix "implication" -------

Patch for 5.2.0 source (not CVS).

--- transports.c        2006-01-01 13:50:18.000000000 +0100
+++ transports-maurice.c        2006-11-06 11:18:49.000000000 +0100
@@ -136,7 +136,7 @@
                if ((flags & STREAM_XPORT_SERVER) == 0) {
                        /* client */
 
-                       if (flags & STREAM_XPORT_CONNECT) {
+                       if (flags & STREAM_XPORT_CONNECT || flags &
STREAM_XPORT_CONNECT_ASYNC) {
                                if (-1 == php_stream_xport_connect(stream, 
name, namelen,
                                                        flags & 
STREAM_XPORT_CONNECT_ASYNC ? 1 : 0,
                                                        timeout, &error_text, 
error_code TSRMLS_CC)) { 

---------------------------------------------

There are other (somehow) related bugs:
http://bugs.php.net/bug.php?id=30386
http://bugs.php.net/bug.php?id=28245





Reproduce code:
---------------
<?php

    $fp = stream_socket_client("tcp://www.php.net:80", $errno, $errstr,
30, STREAM_CLIENT_ASYNC_CONNECT);

    if (!$fp) {

        echo "$errstr ($errno)<br />\n";

    } else {

        var_dump(stream_set_blocking($fp, false));

        fclose($fp);

    }

?>


Expected result:
----------------
If you do not specify STREAM_CLIENT_CONNECT in stream_socket_client the
socket never ever gets connected. Thus, stream_set_blocking should
return FALSE and throw an E_WARNING.
However, as this is a stream function and the stream is still
considered "valid", TRUE might also be all right.

Under Debian Linux (Sarge, Kernel 2.6.8) stream_set_blocking returns
TRUE (which I think is misleading).


Actual result:
--------------
Crashes under Windows XP; returns TRUE on Linux.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=39396&edit=1

Reply via email to