php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39396 stream_set_blocking crashes
Submitted: 2006-11-06 10:33 UTC Modified: 2007-02-24 15:49 UTC
Votes:3
Avg. Score:3.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:3 (100.0%)
From: maurice at iceblog dot de Assigned:
Status: Closed Package: Streams related
PHP Version: 5.2.0 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: maurice at iceblog dot de
New email:
PHP Version: OS:

 

 [2006-11-06 10:33 UTC] 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-06 16:19 UTC] maurice at iceblog dot de
stream_socket_client should at least return FALSE or an error if you just use STREAM_CLIENT_ASYNC_CONNECT without STREAM_CLIENT_CONNECT.
 [2007-02-24 15:49 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC