summaryrefslogtreecommitdiff
path: root/ext/openssl/xp_ssl.c
diff options
context:
space:
mode:
authorChris Wright <github@daverandom.com>2014-08-23 01:40:19 +0100
committerDaniel Lowrey <rdlowrey@php.net>2015-03-05 17:18:14 -0700
commite7df9d710cfb6bbb059ab673bb5851515b2a3aa9 (patch)
tree7894db9712608ac3a76e6600e3dd3d920b3f5f39 /ext/openssl/xp_ssl.c
parentca24d19a895e7b8047db7f43acb041ad288a578f (diff)
downloadphp-git-e7df9d710cfb6bbb059ab673bb5851515b2a3aa9.tar.gz
Fix stream_select() issue with OpenSSL buffer
Ensure data from OpenSSL internal buffer has been transfered to PHP stream buffer before a select() emulation operation is performed Addresses bug #65137 https://bugs.php.net/bug.php?id=65137 Conflicts: ext/openssl/xp_ssl.c
Diffstat (limited to 'ext/openssl/xp_ssl.c')
-rw-r--r--ext/openssl/xp_ssl.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c
index d04b3161b2..ccc5af7df7 100644
--- a/ext/openssl/xp_ssl.c
+++ b/ext/openssl/xp_ssl.c
@@ -2276,7 +2276,20 @@ static int php_openssl_sockop_cast(php_stream *stream, int castas, void **ret TS
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;