Skip to content

Commit c661121

Browse files
committed
Don't block on crypto data inside stream_select()
1 parent d4f727d commit c661121

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

ext/openssl/xp_ssl.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,17 +2284,13 @@ static int php_openssl_sockop_cast(php_stream *stream, int castas, void **ret TS
22842284

22852285
case PHP_STREAM_AS_FD_FOR_SELECT:
22862286
if (ret) {
2287-
if (sslsock->ssl_active) {
2288-
/* OpenSSL has an internal buffer which select() cannot see. If we don't
2289-
fetch it into the stream's buffer, no activity will be reported on the
2290-
stream even though there is data waiting to be read - but we only fetch
2291-
the number of bytes OpenSSL has ready to give us since we weren't asked
2292-
for any data at this stage. This is only likely to cause issues with
2293-
non-blocking streams, but it's harmless to always do it. */
2294-
int bytes;
2295-
while ((bytes = SSL_pending(sslsock->ssl_handle)) > 0) {
2296-
php_stream_fill_read_buffer(stream, (size_t)bytes);
2297-
}
2287+
size_t pending;
2288+
if (stream->writepos == stream->readpos
2289+
&& sslsock->ssl_active
2290+
&& (pending = (size_t)SSL_pending(sslsock->ssl_handle)) > 0) {
2291+
php_stream_fill_read_buffer(stream, pending < stream->chunk_size
2292+
? pending
2293+
: stream->chunk_size);
22982294
}
22992295

23002296
*(int *)ret = sslsock->s.socket;

0 commit comments

Comments
 (0)