From 94e09bfe558656d3f1470dc960b900a951b0dffc Mon Sep 17 00:00:00 2001 From: Joe Cai Date: Mon, 20 Apr 2020 09:03:11 +1000 Subject: Fix #79497: Fix php_openssl_subtract_timeval() I stumbled upon this while debugging a strange issue with stream_socket_client() where it randomly throws out errors when the connection timeout is set to below 1s. The logic to calculate time difference in php_openssl_subtract_timeval() is wrong when a.tv_usec < b.tv_usec, causing connection errors before the timeout is reached. --- ext/openssl/xp_ssl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/openssl/xp_ssl.c') diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c index 88d86c2096..ea29a34058 100644 --- a/ext/openssl/xp_ssl.c +++ b/ext/openssl/xp_ssl.c @@ -2209,8 +2209,8 @@ static struct timeval php_openssl_subtract_timeval(struct timeval a, struct time difference.tv_usec = a.tv_usec - b.tv_usec; if (a.tv_usec < b.tv_usec) { - b.tv_sec -= 1L; - b.tv_usec += 1000000L; + difference.tv_sec -= 1L; + difference.tv_usec += 1000000L; } return difference; -- cgit v1.2.1