@@ -1849,7 +1849,7 @@ static size_t php_openssl_sockop_read(php_stream *stream, char *buf, size_t coun
1849
1849
to hang forever. To avoid this scenario we poll with a timeout before performing
1850
1850
the actual read. If it times out we're finished.
1851
1851
*/
1852
- if (sock -> is_blocked ) {
1852
+ if (sock -> is_blocked && SSL_pending ( sslsock -> ssl_handle ) == 0 ) {
1853
1853
php_openssl_stream_wait_for_data (sock );
1854
1854
if (sock -> timeout_event ) {
1855
1855
stream -> eof = 1 ;
@@ -2176,17 +2176,19 @@ static int php_openssl_sockop_cast(php_stream *stream, int castas, void **ret TS
2176
2176
2177
2177
case PHP_STREAM_AS_FD_FOR_SELECT :
2178
2178
if (ret ) {
2179
- if (sslsock -> ssl_active ) {
2180
- /* OpenSSL has an internal buffer which select() cannot see. If we don't
2181
- fetch it into the stream's buffer, no activity will be reported on the
2182
- stream even though there is data waiting to be read - but we only fetch
2183
- the number of bytes OpenSSL has ready to give us since we weren't asked
2184
- for any data at this stage. This is only likely to cause issues with
2185
- non-blocking streams, but it's harmless to always do it. */
2186
- int bytes ;
2187
- while ((bytes = SSL_pending (sslsock -> ssl_handle )) > 0 ) {
2188
- php_stream_fill_read_buffer (stream , (size_t )bytes );
2189
- }
2179
+ /* OpenSSL has an internal buffer which select() cannot see. If we don't
2180
+ * fetch it into the stream's buffer, no activity will be reported on the
2181
+ * stream even though there is data waiting to be read - but we only fetch
2182
+ * the lower of bytes OpenSSL has ready to give us or chunk_size since we
2183
+ * weren't asked for any data at this stage. This is only likely to cause
2184
+ * issues with non-blocking streams, but it's harmless to always do it. */
2185
+ size_t pending ;
2186
+ if (stream -> writepos == stream -> readpos
2187
+ && sslsock -> ssl_active
2188
+ && (pending = (size_t )SSL_pending (sslsock -> ssl_handle )) > 0 ) {
2189
+ php_stream_fill_read_buffer (stream , pending < stream -> chunk_size
2190
+ ? pending
2191
+ : stream -> chunk_size );
2190
2192
}
2191
2193
2192
2194
* (php_socket_t * )ret = sslsock -> s .socket ;
0 commit comments