Skip to content

Commit ef663d6

Browse files
committed
Fix phpGH-17717: Socket maximum timeout of 2147 seconds?
The fix for phpGH-16809[1] used a way too small timeout maximum on Windows. We correct this. However, later on the timeout is applied to the current timestamp, so we would need to take that into account, but due to the elapsed time between the check and the actual network request, this could not be precise, and the resulting error message would be confusing, since after the developer would adjust the timeout to the reported maximum, the check would fail again, now reporting a lower maximum timeout. Thus we silently cap the value in `php_network_set_limit_time()` to avoid undefined behavior, and are not picky about the usec value (we just assume a second more), since there is a bigger issue, namely that we hit the Y2038 problem on Windows. [1] <php#16810>
1 parent 68d2bc4 commit ef663d6

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

ext/standard/http_fopen_wrapper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
219219
#ifndef PHP_WIN32
220220
const double timeoutmax = (double) PHP_TIMEOUT_ULL_MAX / 1000000.0;
221221
#else
222-
const double timeoutmax = (double) LONG_MAX / 1000000.0;
222+
const double timeoutmax = (double) LONG_MAX + 0.999999;
223223
#endif
224224

225225
if (d > timeoutmax) {

main/network.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,14 @@ static inline void php_network_set_limit_time(struct timeval *limit_time,
319319
struct timeval *timeout)
320320
{
321321
gettimeofday(limit_time, NULL);
322+
# ifdef PHP_WIN32
323+
/* cap timeout (we're not picky regarding usec) */
324+
if (limit_time->tv_sec > (LONG_MAX - timeout->tv_sec) + 1) {
325+
limit_time->tv_sec = LONG_MAX;
326+
limit_time->tv_usec = 999999;
327+
return;
328+
}
329+
# endif
322330
limit_time->tv_sec += timeout->tv_sec;
323331
limit_time->tv_usec += timeout->tv_usec;
324332
if (limit_time->tv_usec >= 1000000) {

0 commit comments

Comments
 (0)