php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41489 stream_select does not work on ssl stream_socket_server (works in 5.2.1!) on 64b
Submitted: 2007-05-24 13:09 UTC Modified: 2008-11-03 13:31 UTC
Votes:6
Avg. Score:4.5 ± 0.8
Reproduced:5 of 5 (100.0%)
Same Version:5 (100.0%)
Same OS:4 (80.0%)
From: n dot escuder at intra-links dot com Assigned: iliaa (profile)
Status: Closed Package: Streams related
PHP Version: 5.2-cvs OS: Linux 2.6
Private report: No CVE-ID: None
 [2007-05-24 13:09 UTC] n dot escuder at intra-links dot com
Description:
------------
When creating an socket server in ssl mode stream_select don't work.

In PHP 5.2.1 all work fine the bug is in PHP 5.2.2.

Reproduce code:
---------------
server.php:

$options = array( "ssl" => array( "allow_self_signed" => true, "verify_peer" => false, "local_cert" => "/www/conf/ssl/server.pem" ) );
$context = stream_context_create();
stream_context_set_option( $context, $options );

$s = stream_socket_server( "ssl://0.0.0.0:6310", $errno, $errstr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $context );
while ( 1 ) {
   $read = array( $s );
   $wr = null;
   $ed = null;
   if ( stream_select( $read, $wr, $ed, 0, 500 ) > 0 ) {
      echo "ACCEPT\n";
   }
}

client.php:

$s = stream_socket_client( "ssl://localhost:6310" );
$s->write("toto\r\n\r\n");
sleep( 1 );


Expected result:
----------------
when running server.php we must go "ACCEPT" onto the screen.

Actual result:
--------------
nothing

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-27 17:06 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.


 [2007-06-29 19:59 UTC] n dot escuder at intra-links dot com
Ok now it's good on 32 bit plateform but not on 64 bit.

If i compile 32 bit version of PHP this works.

If i compile 64 bit version of PHP your patch don't work.
 [2007-07-01 01:50 UTC] sniper@php.net
Ilia, can you check it out please?
 [2007-07-02 16:12 UTC] iliaa@php.net
I've just tried it on a 64 bit opteron and it definitely goes into 
"ACCEPT"
 [2007-07-09 13:22 UTC] n dot escuder at intra-links dot com
I have sent an email to iliaa@php.net on 03/07/2007 with no answer.

So i reopen the bug.

Email content :

I just retry with php 5.2.3 and php 5.2.4-dev

On 64 bit plateform the ACCEPT never arrive.

With PHP 5.2.1 on the same plateform ACCEPT arrive.

I can do some try if you need. Email me.

I don't known what to do ... And i need this function ;o)
 [2007-07-09 15:24 UTC] sniper@php.net
Please give more information about your (64bit) system.
And also the full configure line.

I can NOT reproduce this using latest CVS on this system:

# uname -a
Linux linux5 2.6.20-1.2944.fc6 #1 SMP Tue Apr 10 17:46:00 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux

(fedora 6)

 [2007-07-09 17:07 UTC] n dot escuder at intra-links dot com
Linux zelda.intra-links.dev 2.6.21.4-atl-smp #1 SMP Mon Jun 25 20:28:57 CEST 2007 x86_64 GNU/Linux

OpenSSL 0.9.8e 23 Feb 2007

I omit to say that PHP is the CLI Version.

Build script of PHP :

export EXTENSION_DIR=/usr/lib/php/extensions  &&
ARGS="--prefix=/usr \
        --sysconfdir=/etc \
        --with-config-file-path=/etc \
        --with-zlib-dir=/usr/lib \
        --with-pear \
        --enable-dom \
        --enable-overload \
        --enable-pcntl \
        --enable-pdo \
        --enable-simplexml \
        --enable-zip \
        --enable-json \
        --with-bz2=shared \
        --with-curl=shared \
        --with-fam=shared \
        --with-gettext=shared \
        --with-iconv=shared \
        --with-imap=shared \
        --with-imap-ssl=shared \
        --with-mysql=shared \
        --with-openssl=shared \
        --with-pdo-mysql=shared \
        --with-pdo-sqlite=/usr \
        --with-xml=shared \
        --with-simplexml=shared \
        --with-xmlreader=shared \
        --with-xmlwriter=shared \
        --enable-bcmath=shared \
        --enable-calendar=shared \
        --enable-ctype=shared \
        --enable-exif=shared \
        --enable-ftp=shared \
        --enable-hash=shared \
        --enable-mbstring=shared \
        --enable-sockets=shared \
        --enable-tokenizer=shared \
        --enable-xmlreader=shared \
        --enable-xmlwriter=shared \
        --without-sqlite \
        --disable-cgi" &&
./configure $ARGS &&
make &&
make install 

It's an LFS OS. PHP is the core of the plateform it manage services and events between processs with RPC and more...

I can give you an access if you need it.
 [2007-07-10 11:30 UTC] jani@php.net
Try building the latest 5.2 CVS snapshot without compiling anything as shared. And make sure you don't load any php.ini by passing -n to CLI when you run the scripts.
 [2007-07-10 12:36 UTC] n dot escuder at intra-links dot com
I did it with php5.2-200707101030

I ran with -n and the problems stay. ACCEPT never arrive.
 [2007-07-10 14:13 UTC] jani@php.net
Did you try cutting the configure options to the bare minimum you need for the test scripts to run and did you use --disable-all? If not, do this.
 [2007-07-10 14:49 UTC] n dot escuder at intra-links dot com
I just retry with :

./configure --prefix=/usr --sysconfdir=/etc --disable-all --enable-sockets --with-openssl --disable-cgi       

and the same append.
 [2007-07-12 20:42 UTC] jani@php.net
I just realized that of course I don't have this cert/www/conf/ssl/server.pem here. But it can't be the cause..can it?

 [2007-07-13 21:29 UTC] n dot escuder at intra-links dot com
I try without any certificat and the same problem appear.

I try launch server.php with php-5.2-dev and client with php-5.2.1 and the same problem appear.

So i decide to lookup into the code. A strange result append i try to explain :

code in ext/standard/streamsfuncs.c :

    retval = php_select(max_fd+1, &rfds, &wfds, &efds, tv_p);
printf("%d %d\n", max_fd, retval );
    if (retval == -1) {
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to select [%d]: %s (max_fd=%d)",
                errno, strerror(errno), max_fd);
        RETURN_FALSE;
    }
printf("%d\n", retval );
    if (r_array != NULL) stream_array_from_fd_set(r_array, &rfds TSRMLS_CC);
    if (w_array != NULL) stream_array_from_fd_set(w_array, &wfds TSRMLS_CC);
    if (e_array != NULL) stream_array_from_fd_set(e_array, &efds TSRMLS_CC);
printf("%d\n", retval );
    RETURN_LONG(retval);


As you can see i had three printf for debug :o)

I add an var_dump to the result of stream_select in server.php
The strange result i have after i launch client.php is :

3 1 -> First printf with max_fd and retval
1 -> Second printf with retval
0 -> Third printf with retval but the value as changed ....
int(0) -> The var_dump in server.php

So the value change between the second and third printf ;o)

I hope this help
 [2007-11-20 09:44 UTC] n dot escuder at intra-links dot com
The same appear in 5.2.5.

It's seem to be a memory corruption problem.

The retval value change in PHP_FUNCTION(stream_select)

just after executing the line :
if (r_array != NULL) stream_array_from_fd_set(r_array, &rfds TSRMLS_CC);

Please tell me how can i help you to solve this problem.

I can't upgrade from PHP 5.2.1.

See You
 [2008-02-08 17:33 UTC] jjohnson at insidesales dot com
I'm using 5.2.5 and having similar issues with stream_select and a tcp stream_socket_server.  I'm using NULL for the timeout, so that the function call shouldn't return until a stream is available.


$sock = stream_socket_server("tcp://".$address.":".$port, $errno, $errstr);
$ready = stream_select($reads, $writes, $e = NULL, NULL);

stream_select is returning when there is a stream available, but the return value is 0 (I've verified that $ready == 0 and $ready !== false).
 [2008-02-14 12:59 UTC] n dot escuder at intra-links dot com
After searching in the change since PHP 5.2.1 I found the change who break this.

The change is in the IMAP extension : 

diff -Naur php-5.2.5/ext/imap/config.m4 php-5.2.5-atl/ext/imap/config.m4
--- php-5.2.5/ext/imap/config.m4        2007-02-11 10:25:32.000000000 +0100
+++ php-5.2.5-atl/ext/imap/config.m4    2007-01-23 13:37:21.000000000 +0100
@@ -1,5 +1,5 @@
 dnl
-dnl $Id: config.m4,v 1.69.4.7 2007/02/11 09:25:32 tony2001 Exp $
+dnl $Id: config.m4,v 1.69.4.6 2007/01/23 12:37:21 bjori Exp $
 dnl
 
 AC_DEFUN([IMAP_INC_CHK],[if test -r "$i$1/c-client.h"; then
@@ -137,7 +137,7 @@
     if test "$ac_cv_utf8_mime2text" = "new"; then
       AC_DEFINE(HAVE_NEW_MIME2TEXT, 1, [Whether utf8_mime2text() has new signature])
     fi
-    CFLAGS=$old_CFLAGS
+    CFLAGS=$old_CPPFLAGS
 
     old_CFLAGS=$CFLAGS
     CFLAGS="-I$IMAP_INC_DIR"
@@ -152,7 +152,7 @@
          ac_cv_u8t_canonical=no
       ])
     )
-    CFLAGS=$old_CFLAGS
+    CFLAGS=$old_CPPFLAGS
 
     if test "$ac_cv_u8t_canonical" = "no" && test "$ac_cv_utf8_mime2text" = "new"; then
                AC_MSG_ERROR([utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.])

I don't understand why this change break select on ssl but i think it break something in configure. If i revert this change on php-5.2.5 code tree and i do an autoreconf command and compile the code, all works fine.
 [2008-11-02 12:44 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2008-11-03 13:28 UTC] n dot escuder at intra-links dot com
Ok now it's good we got ACCEPT can i not what the problem was ?
 [2008-11-03 13:31 UTC] jani@php.net
Seems like the patch you provided had been applied (or same change, without any links to this report though).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 01 20:01:29 2024 UTC