Skip to content

Commit edb2799

Browse files
committed
Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5: Bug #41631: Fix regression from first attempt (6569db8) Bug #67965: Fix blocking behavior in non-blocking crypto streams
2 parents da7c87e + bf2f80b commit edb2799

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ PHP NEWS
3131
. Fixed bug #67839 (mysqli does not handle 4-byte floats correctly). (Keyur)
3232

3333
- OpenSSL:
34+
. Fixed bug #41631 (socket timeouts not honored in blocking SSL reads).
35+
(Daniel Lowrey)
3436
. Fixed bug #67850 (extension won't build if openssl compiled without SSLv3).
3537
(Daniel Lowrey)
3638

ext/openssl/xp_ssl.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,7 +1849,7 @@ static size_t php_openssl_sockop_read(php_stream *stream, char *buf, size_t coun
18491849
to hang forever. To avoid this scenario we poll with a timeout before performing
18501850
the actual read. If it times out we're finished.
18511851
*/
1852-
if (sock->is_blocked) {
1852+
if (sock->is_blocked && SSL_pending(sslsock->ssl_handle) == 0) {
18531853
php_openssl_stream_wait_for_data(sock);
18541854
if (sock->timeout_event) {
18551855
stream->eof = 1;
@@ -2176,17 +2176,19 @@ static int php_openssl_sockop_cast(php_stream *stream, int castas, void **ret TS
21762176

21772177
case PHP_STREAM_AS_FD_FOR_SELECT:
21782178
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);
21902192
}
21912193

21922194
*(php_socket_t *)ret = sslsock->s.socket;

0 commit comments

Comments
 (0)