ID:               41631
 User updated by:  david at acz dot org
 Reported By:      david at acz dot org
 Status:           Open
 Bug Type:         OpenSSL related
 Operating System: SuSE Linux
 PHP Version:      5.2.3
 New Comment:

I have a (partial?) fix:

Index: main/streams/xp_socket.c
===================================================================
RCS file: /repository/php-src/main/streams/xp_socket.c,v
retrieving revision 1.33.2.2.2.4
diff -u -p -d -r1.33.2.2.2.4 xp_socket.c
--- main/streams/xp_socket.c    1 Jan 2007 09:36:12 -0000      
1.33.2.2.2.4
+++ main/streams/xp_socket.c    8 Jun 2007 15:55:57 -0000
@@ -103,7 +103,7 @@ retry:
        return didwrite;
 }

-static void php_sock_stream_wait_for_data(php_stream *stream,
php_netstream_data_t *sock TSRMLS_DC)
+void php_sock_stream_wait_for_data(php_stream *stream,
php_netstream_data_t *sock TSRMLS_DC)
 {
        int retval;
        struct timeval *ptimeout;
Index: ext/openssl/xp_ssl.c
===================================================================
RCS file: /repository/php-src/ext/openssl/xp_ssl.c,v
retrieving revision 1.22.2.3.2.8
diff -u -p -d -r1.22.2.3.2.8 xp_ssl.c
--- ext/openssl/xp_ssl.c        27 May 2007 17:05:51 -0000     
1.22.2.3.2.8
+++ ext/openssl/xp_ssl.c        8 Jun 2007 15:55:57 -0000
@@ -35,6 +35,8 @@
 #include <sys/select.h>
 #endif

+void php_sock_stream_wait_for_data(php_stream *stream,
php_netstream_data_t *sock TSRMLS_DC);
+
 int php_openssl_apply_verification_policy(SSL *ssl, X509 *peer,
php_stream *stream TSRMLS_DC);
 SSL *php_SSL_new_from_context(SSL_CTX *ctx, php_stream *stream
TSRMLS_DC);
 int php_openssl_get_x509_list_id(void);
@@ -219,6 +221,12 @@ static size_t php_openssl_sockop_read(ph
        php_openssl_netstream_data_t *sslsock =
(php_openssl_netstream_data_t*)stream->abstract;
        int nr_bytes = 0;

+       if (sslsock->s.is_blocked) {
+               php_sock_stream_wait_for_data(stream, &(sslsock->s)
TSRMLS_CC);
+               if (sslsock->s.timeout_event)
+                       return 0;
+       }
+
        if (sslsock->ssl_active) {
                int retry = 1;


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

[2007-06-08 01:15:24] david at acz dot org

Description:
------------
The default socket timeout does not work with SSL streams.  An strace
shows PHP calls read(2) and blocks forever.

Reproduce code:
---------------
Create sleepforever.php:

<? for(;;) sleep(1); ?>

Try it with HTTP:

$ php -n -r 'ini_set("default_socket_timeout", 1);
fopen("http://127.0.0.1/sleepforever.php";, "r");'

Now try it with HTTPS:

$ time php -n -r 'ini_set("default_socket_timeout", 1);
fopen("https://127.0.0.1/sleepforever.php";, "r");'


Expected result:
----------------
Warning: fopen(http://127.0.0.1/sleepforever.php): failed to open
stream: HTTP request failed!  in Command line code on line 1

real    0m2.052s
user    0m0.020s
sys     0m0.010s


Actual result:
--------------
The process blocks forever.  An strace shows this:

connect(3, {sa_family=AF_INET, sin_port=htons(443),
sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in
progress)
poll([{fd=3, events=POLLIN|POLLOUT|POLLERR|POLLHUP, revents=POLLOUT}],
1, 1000) = 1
getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
fcntl64(3, F_SETFL, O_RDWR)             = 0
write(3, "\200j\1\3\1\0Q\0\0\0\20\0\0\26\0\0\23\0\0\n\7\0\300\0\0"...,
108) = 108
read(3, "\26\3\1\0J\2\0", 7)            = 7
*** ELIDED ***
write(3, "\27\3\1\0\30N~h\231u\31S]94^\253\235\26t\324\214\t/\261"...,
29) = 29
poll([{fd=3, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0
read(3, *** THIS BLOCKS FOREVER ***



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


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

Reply via email to