diff --git a/build/php.m4 b/build/php.m4 index e13fc3367ea1e..e772814f0e12e 100644 --- a/build/php.m4 +++ b/build/php.m4 @@ -2430,6 +2430,7 @@ AC_DEFUN([PHP_CHECK_STDINT_TYPES], [ AC_CHECK_SIZEOF([long long]) AC_CHECK_SIZEOF([size_t]) AC_CHECK_SIZEOF([off_t]) + AC_CHECK_SIZEOF([time_t]) AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t], [], [ AC_MSG_ERROR([One of the intN_t or uintN_t types is not available]) ], [ diff --git a/ext/session/session.c b/ext/session/session.c index dd780f4afd424..00d8c81cda729 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -1178,7 +1178,21 @@ CACHE_LIMITER_FUNC(public) /* {{{ */ time_t now; gettimeofday(&tv, NULL); - now = tv.tv_sec + PS(cache_expire) * 60; + zend_long cache_expire = PS(cache_expire); + +#if SIZEOF_TIME_T == 4 || SIZEOF_TIME_T == 8 + const time_t max = (time_t)((zend_ulong)~0 >> 1); +#else + const time_t max = (time_t)((~(time_t)0) >> 1); +#endif + + if (cache_expire < 0) { + now = tv.tv_sec; + } else if ((cache_expire / 60) > (max - (zend_long)max)) { + now = max; + } else { + now = tv.tv_sec + cache_expire * 60; + } memcpy(buf, EXPIRES, sizeof(EXPIRES) - 1); strcpy_gmt(buf + sizeof(EXPIRES) - 1, &now); ADD_HEADER(buf); diff --git a/ext/session/tests/session_cache_expire_basic.phpt b/ext/session/tests/session_cache_expire_basic.phpt index 9873b80da2b58..dd5964e0a362f 100644 --- a/ext/session/tests/session_cache_expire_basic.phpt +++ b/ext/session/tests/session_cache_expire_basic.phpt @@ -22,11 +22,11 @@ var_dump(session_cache_expire()); echo "Done"; ob_end_flush(); ?> ---EXPECT-- +--EXPECTF-- *** Testing session_cache_expire() : basic functionality *** int(180) int(180) -int(1234567890) +int(%d) bool(true) int(180) bool(true) diff --git a/ext/session/tests/session_cache_expire_oflow.phpt b/ext/session/tests/session_cache_expire_oflow.phpt new file mode 100644 index 0000000000000..39a6cd13f7dbc --- /dev/null +++ b/ext/session/tests/session_cache_expire_oflow.phpt @@ -0,0 +1,27 @@ +--TEST-- +session_cache_expire() overflow +--EXTENSIONS-- +session +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +*** Testing session_cache_expire() : overflow test *** +int(180) +int(%s) +Done + diff --git a/ext/session/tests/session_cache_expire_variation1.phpt b/ext/session/tests/session_cache_expire_variation1.phpt index 6383092f56257..044275baee627 100644 --- a/ext/session/tests/session_cache_expire_variation1.phpt +++ b/ext/session/tests/session_cache_expire_variation1.phpt @@ -24,11 +24,11 @@ var_dump(session_cache_expire()); echo "Done"; ob_end_flush(); ?> ---EXPECT-- +--EXPECTF-- *** Testing session_cache_expire() : variation *** int(360) int(360) -int(1234567890) +int(%d) bool(true) int(180) bool(true) diff --git a/ext/session/tests/session_cache_expire_variation2.phpt b/ext/session/tests/session_cache_expire_variation2.phpt index e3c598affb8fb..04cf13323ab72 100644 --- a/ext/session/tests/session_cache_expire_variation2.phpt +++ b/ext/session/tests/session_cache_expire_variation2.phpt @@ -23,11 +23,11 @@ var_dump(session_cache_expire()); echo "Done"; ob_end_flush(); ?> ---EXPECT-- +--EXPECTF-- *** Testing session_cache_expire() : variation *** int(360) int(360) -int(1234567890) +int(%d) bool(true) int(180) bool(true) diff --git a/ext/session/tests/session_cache_expire_variation3.phpt b/ext/session/tests/session_cache_expire_variation3.phpt index a243418001f34..8674dab2b15bd 100644 --- a/ext/session/tests/session_cache_expire_variation3.phpt +++ b/ext/session/tests/session_cache_expire_variation3.phpt @@ -26,7 +26,7 @@ var_dump(ini_get("session.cache_expire")); echo "Done"; ob_end_flush(); ?> ---EXPECT-- +--EXPECTF-- *** Testing session_cache_expire() : variation *** string(3) "180" int(180) @@ -34,9 +34,9 @@ string(3) "180" int(180) string(10) "1234567890" bool(true) -int(1234567890) +int(%d) string(10) "1234567890" bool(true) -int(1234567890) +int(%d) string(10) "1234567890" Done