diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2020-06-09 12:42:02 +0200 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2020-06-09 16:45:34 +0200 |
commit | eadd98070662f0c56d7138bcb2a42d397c11f6e4 (patch) | |
tree | b1bb02e3aad7e4543cfe63c4d984d7b296ac9752 | |
parent | eac700b1e664ef916da66bd919127d0292a6c435 (diff) | |
download | php-git-eadd98070662f0c56d7138bcb2a42d397c11f6e4.tar.gz |
Fix #62890: default_socket_timeout=-1 causes connection to timeout
While unencrypted connections ignore negative timeouts, SSL/TLS
connections did not special case that, and so always failed due to
timeout.
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | ext/openssl/tests/bug62890.phpt | 15 | ||||
-rw-r--r-- | ext/openssl/xp_ssl.c | 4 |
3 files changed, 21 insertions, 2 deletions
@@ -10,6 +10,10 @@ PHP NEWS - Filter: . Fixed bug #73527 (Invalid memory access in php_filter_strip). (cmb) +- OpenSSL: + . Fixed bug #62890 (default_socket_timeout=-1 causes connection to timeout). + (cmb) + - PDO SQLite: . Fixed bug #79664 (PDOStatement::getColumnMeta fails on empty result set). (cmb) diff --git a/ext/openssl/tests/bug62890.phpt b/ext/openssl/tests/bug62890.phpt new file mode 100644 index 0000000000..b400b0e5ef --- /dev/null +++ b/ext/openssl/tests/bug62890.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #62890 (default_socket_timeout=-1 causes connection to timeout) +--SKIPIF-- +<?php +if (!extension_loaded('openssl')) die('skip openssl extension not available'); +if (getenv('SKIP_ONLINE_TESTS')) die('skip online test'); +?> +--INI-- +default_socket_timeout=-1 +--FILE-- +<?php +var_dump((bool) file_get_contents('https://php.net')); +?> +--EXPECT-- +bool(true) diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c index ea29a34058..d79c325d02 100644 --- a/ext/openssl/xp_ssl.c +++ b/ext/openssl/xp_ssl.c @@ -1912,7 +1912,7 @@ static int php_openssl_enable_crypto(php_stream *stream, } timeout = sslsock->is_client ? &sslsock->connect_timeout : &sslsock->s.timeout; - has_timeout = !sslsock->s.is_blocked && (timeout->tv_sec || timeout->tv_usec); + has_timeout = !sslsock->s.is_blocked && (timeout->tv_sec > 0 || (timeout->tv_sec == 0 && timeout->tv_usec)); /* gettimeofday is not monotonic; using it here is not strictly correct */ if (has_timeout) { gettimeofday(&start_time, NULL); @@ -2064,7 +2064,7 @@ static size_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, siz sslsock->s.is_blocked = 0; } - if (!sslsock->s.is_blocked && timeout && (timeout->tv_sec || timeout->tv_usec)) { + if (!sslsock->s.is_blocked && timeout && (timeout->tv_sec > 0 || (timeout->tv_sec == 0 && timeout->tv_usec))) { has_timeout = 1; /* gettimeofday is not monotonic; using it here is not strictly correct */ gettimeofday(&start_time, NULL); |