diff options
author | Jakub Zelenka <bukka@php.net> | 2019-01-17 18:05:13 +0000 |
---|---|---|
committer | Jakub Zelenka <bukka@php.net> | 2019-01-25 14:13:11 +0000 |
commit | dc2ffdeed7d5c17eeb4f706f530eccafb425f92a (patch) | |
tree | 4273793f7b90dd9ff2c94a08d3a1025192894e33 /ext/openssl/xp_ssl.c | |
parent | d9b29029f9793ffdefbd575dd26cc54c78c0a1cf (diff) | |
download | php-git-dc2ffdeed7d5c17eeb4f706f530eccafb425f92a.tar.gz |
Fix bug #77390 (feof might hang on TLS streams in case of fragmented TLS records)
Simplified version of the fix from Abyl Valg so credit to him.
Diffstat (limited to 'ext/openssl/xp_ssl.c')
-rw-r--r-- | ext/openssl/xp_ssl.c | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c index a5a4c4dbfb..5117eb2e99 100644 --- a/ext/openssl/xp_ssl.c +++ b/ext/openssl/xp_ssl.c @@ -2405,30 +2405,22 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val alive = 0; } else if (php_pollfd_for(sslsock->s.socket, PHP_POLLREADABLE|POLLPRI, &tv) > 0) { if (sslsock->ssl_active) { - int n; - - do { - n = SSL_peek(sslsock->ssl_handle, &buf, sizeof(buf)); - if (n <= 0) { - int err = SSL_get_error(sslsock->ssl_handle, n); - - if (err == SSL_ERROR_SYSCALL) { + int n = SSL_peek(sslsock->ssl_handle, &buf, sizeof(buf)); + if (n <= 0) { + int err = SSL_get_error(sslsock->ssl_handle, n); + switch (err) { + case SSL_ERROR_SYSCALL: alive = php_socket_errno() == EAGAIN; break; - } - - if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE) { - /* re-negotiate */ - continue; - } - - /* any other problem is a fatal error */ - alive = 0; + case SSL_ERROR_WANT_READ: + case SSL_ERROR_WANT_WRITE: + alive = 1; + break; + default: + /* any other problem is a fatal error */ + alive = 0; } - /* either peek succeeded or there was an error; we - * have set the alive flag appropriately */ - break; - } while (1); + } } else if (0 == recv(sslsock->s.socket, &buf, sizeof(buf), MSG_PEEK) && php_socket_errno() != EAGAIN) { alive = 0; } |