Skip to content

Commit 94e09bf

Browse files
joec4inikic
authored andcommitted
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.
1 parent d31ccb5 commit 94e09bf

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ PHP NEWS
1515
. Fixed bug #79441 (Segfault in mb_chr() if internal encoding is unsupported).
1616
(Girgias)
1717

18+
- OpenSSL:
19+
. Fixed bug #79497 (stream_socket_client() throws an unknown error sometimes
20+
with <1s timeout). (Joe Cai)
21+
1822
- Standard:
1923
. Fixed bug #79468 (SIGSEGV when closing stream handle with a stream filter
2024
appended). (dinosaur)

ext/openssl/xp_ssl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,8 +2209,8 @@ static struct timeval php_openssl_subtract_timeval(struct timeval a, struct time
22092209
difference.tv_usec = a.tv_usec - b.tv_usec;
22102210

22112211
if (a.tv_usec < b.tv_usec) {
2212-
b.tv_sec -= 1L;
2213-
b.tv_usec += 1000000L;
2212+
difference.tv_sec -= 1L;
2213+
difference.tv_usec += 1000000L;
22142214
}
22152215

22162216
return difference;

0 commit comments

Comments
 (0)