Skip to content

Commit eadd980

Browse files
committed
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.
1 parent eac700b commit eadd980

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ PHP NEWS
1010
- Filter:
1111
. Fixed bug #73527 (Invalid memory access in php_filter_strip). (cmb)
1212

13+
- OpenSSL:
14+
. Fixed bug #62890 (default_socket_timeout=-1 causes connection to timeout).
15+
(cmb)
16+
1317
- PDO SQLite:
1418
. Fixed bug #79664 (PDOStatement::getColumnMeta fails on empty result set).
1519
(cmb)

ext/openssl/tests/bug62890.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #62890 (default_socket_timeout=-1 causes connection to timeout)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('openssl')) die('skip openssl extension not available');
6+
if (getenv('SKIP_ONLINE_TESTS')) die('skip online test');
7+
?>
8+
--INI--
9+
default_socket_timeout=-1
10+
--FILE--
11+
<?php
12+
var_dump((bool) file_get_contents('https://php.net'));
13+
?>
14+
--EXPECT--
15+
bool(true)

ext/openssl/xp_ssl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,7 @@ static int php_openssl_enable_crypto(php_stream *stream,
19121912
}
19131913

19141914
timeout = sslsock->is_client ? &sslsock->connect_timeout : &sslsock->s.timeout;
1915-
has_timeout = !sslsock->s.is_blocked && (timeout->tv_sec || timeout->tv_usec);
1915+
has_timeout = !sslsock->s.is_blocked && (timeout->tv_sec > 0 || (timeout->tv_sec == 0 && timeout->tv_usec));
19161916
/* gettimeofday is not monotonic; using it here is not strictly correct */
19171917
if (has_timeout) {
19181918
gettimeofday(&start_time, NULL);
@@ -2064,7 +2064,7 @@ static size_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, siz
20642064
sslsock->s.is_blocked = 0;
20652065
}
20662066

2067-
if (!sslsock->s.is_blocked && timeout && (timeout->tv_sec || timeout->tv_usec)) {
2067+
if (!sslsock->s.is_blocked && timeout && (timeout->tv_sec > 0 || (timeout->tv_sec == 0 && timeout->tv_usec))) {
20682068
has_timeout = 1;
20692069
/* gettimeofday is not monotonic; using it here is not strictly correct */
20702070
gettimeofday(&start_time, NULL);

0 commit comments

Comments
 (0)