diff options
author | Daniel Lowrey <rdlowrey@php.net> | 2015-03-05 17:53:04 -0700 |
---|---|---|
committer | Daniel Lowrey <rdlowrey@php.net> | 2015-03-05 17:53:04 -0700 |
commit | 88cfc6ccb6594e8bacd4adce45094dc2d4d65eac (patch) | |
tree | 303be68f46f6c165b697252ecd483a5ef4835233 | |
parent | 28e42b1deda228402aa768b78e086dc785bb10b0 (diff) | |
parent | e7df9d710cfb6bbb059ab673bb5851515b2a3aa9 (diff) | |
download | php-git-88cfc6ccb6594e8bacd4adce45094dc2d4d65eac.tar.gz |
Merge branch 'PHP-5.6'
* PHP-5.6:
Fix stream_select() issue with OpenSSL buffer
Conflicts:
main/streams/streams.c
-rw-r--r-- | ext/openssl/xp_ssl.c | 15 | ||||
-rw-r--r-- | main/php_streams.h | 3 | ||||
-rw-r--r-- | main/streams/streams.c | 2 |
3 files changed, 18 insertions, 2 deletions
diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c index 9de0dcbef2..0bb22a678c 100644 --- a/ext/openssl/xp_ssl.c +++ b/ext/openssl/xp_ssl.c @@ -2498,7 +2498,20 @@ static int php_openssl_sockop_cast(php_stream *stream, int castas, void **ret) case PHP_STREAM_AS_FD_FOR_SELECT: if (ret) { - *(php_socket_t *)ret = sslsock->s.socket; + if (sslsock->ssl_active) { + /* OpenSSL has an internal buffer which select() cannot see. If we don't + fetch it into the stream's buffer, no activity will be reported on the + stream even though there is data waiting to be read - but we only fetch + the number of bytes OpenSSL has ready to give us since we weren't asked + for any data at this stage. This is only likely to cause issues with + non-blocking streams, but it's harmless to always do it. */ + int bytes; + while ((bytes = SSL_pending(sslsock->ssl_handle)) > 0) { + php_stream_fill_read_buffer(stream, (size_t)bytes); + } + } + + *(int *)ret = sslsock->s.socket; } return SUCCESS; diff --git a/main/php_streams.h b/main/php_streams.h index 3035bd560b..a21d442095 100644 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -307,6 +307,9 @@ PHPAPI size_t _php_stream_write(php_stream *stream, const char *buf, size_t coun #define php_stream_write_string(stream, str) _php_stream_write(stream, str, strlen(str)) #define php_stream_write(stream, buf, count) _php_stream_write(stream, (buf), (count)) +PHPAPI void _php_stream_fill_read_buffer(php_stream *stream, size_t size); +#define php_stream_fill_read_buffer(stream, size) _php_stream_fill_read_buffer((stream), (size)) + #ifdef ZTS PHPAPI size_t _php_stream_printf(php_stream *stream, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4); #else diff --git a/main/streams/streams.c b/main/streams/streams.c index c47fe0d940..64b5470738 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -565,7 +565,7 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov /* {{{ generic stream operations */ -static void php_stream_fill_read_buffer(php_stream *stream, size_t size) +PHPAPI void _php_stream_fill_read_buffer(php_stream *stream, size_t size) { /* allocate/fill the buffer */ |