From cd263d0dafffd4213f122d2f19661d7631b5f99a Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 9 Jun 2020 12:42:02 +0200 Subject: [PATCH] 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. --- ext/openssl/tests/bug62890.phpt | 15 +++++++++++++++ ext/openssl/xp_ssl.c | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 ext/openssl/tests/bug62890.phpt diff --git a/ext/openssl/tests/bug62890.phpt b/ext/openssl/tests/bug62890.phpt new file mode 100644 index 0000000000000..b400b0e5ef741 --- /dev/null +++ b/ext/openssl/tests/bug62890.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #62890 (default_socket_timeout=-1 causes connection to timeout) +--SKIPIF-- + +--INI-- +default_socket_timeout=-1 +--FILE-- + +--EXPECT-- +bool(true) diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c index ea29a340586ca..d79c325d028c8 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);