]> granicus.if.org Git - php/commitdiff
Fix #79497: Fix php_openssl_subtract_timeval()
authorJoe Cai <joe.cai@bigcommerce.com>
Sun, 19 Apr 2020 23:03:11 +0000 (09:03 +1000)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 20 Apr 2020 08:25:54 +0000 (10:25 +0200)
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.

NEWS
ext/openssl/xp_ssl.c

diff --git a/NEWS b/NEWS
index adbaf6223e56c0bec2e1082f1713dc870da30194..8f00881b2956b82ae38d16754befa5eb4a06033d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,10 @@ PHP                                                                        NEWS
   . Fixed bug #79441 (Segfault in mb_chr() if internal encoding is unsupported).
     (Girgias)
 
+- OpenSSL:
+  . Fixed bug #79497 (stream_socket_client() throws an unknown error sometimes
+    with <1s timeout). (Joe Cai)
+
 - Standard:
   . Fixed bug #79468 (SIGSEGV when closing stream handle with a stream filter
     appended). (dinosaur)
index 88d86c2096facebc6e3190b69ba2577c54d38caf..ea29a340586ca0076be3f667dc72cf92621f614a 100644 (file)
@@ -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;