Skip to content

Commit 34fbf71

Browse files
committed
ext/session: Fix cache_expire ini overflow/underflow.
Setting with PHP_INT_MIN/PHP_INT_MAX lead to these. ``` ext/session/session.c:1181:37: runtime error: signed integer overflow: -9223372036854775808 * 60 cannot be represented in type 'long int' ext/session/session.c:1181:37: runtime error: signed integer overflow: 9223372036854775807 * 60 cannot be represented in type 'long int' ```
1 parent d613c0e commit 34fbf71

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

ext/session/session.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,23 @@ static PHP_INI_MH(OnUpdateCookieLifetime) /* {{{ */
710710
}
711711
/* }}} */
712712

713+
static PHP_INI_MH(OnUpdateCacheExpire)
714+
{
715+
SESSION_CHECK_ACTIVE_STATE;
716+
SESSION_CHECK_OUTPUT_STATE;
717+
718+
#ifdef ZEND_ENABLE_ZVAL_LONG64
719+
const zend_long maxexpire = ((ZEND_LONG_MAX - INT_MAX) / 60) - 1;
720+
#else
721+
const zend_long maxexpire = ((ZEND_LONG_MAX / 2) / 60) - 1;
722+
#endif
723+
zend_long v = (zend_long)atol(ZSTR_VAL(new_value));
724+
if (v < 0 || v > maxexpire) {
725+
return SUCCESS;
726+
}
727+
return OnUpdateLongGEZero(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
728+
}
729+
713730

714731
static PHP_INI_MH(OnUpdateSessionLong) /* {{{ */
715732
{
@@ -818,7 +835,7 @@ PHP_INI_BEGIN()
818835
STD_PHP_INI_BOOLEAN("session.use_strict_mode", "0", PHP_INI_ALL, OnUpdateSessionBool, use_strict_mode, php_ps_globals, ps_globals)
819836
STD_PHP_INI_ENTRY("session.referer_check", "", PHP_INI_ALL, OnUpdateSessionString, extern_referer_chk, php_ps_globals, ps_globals)
820837
STD_PHP_INI_ENTRY("session.cache_limiter", "nocache", PHP_INI_ALL, OnUpdateSessionString, cache_limiter, php_ps_globals, ps_globals)
821-
STD_PHP_INI_ENTRY("session.cache_expire", "180", PHP_INI_ALL, OnUpdateSessionLong, cache_expire, php_ps_globals, ps_globals)
838+
STD_PHP_INI_ENTRY("session.cache_expire", "180", PHP_INI_ALL, OnUpdateCacheExpire, cache_expire, php_ps_globals, ps_globals)
822839
STD_PHP_INI_BOOLEAN("session.use_trans_sid", "0", PHP_INI_ALL, OnUpdateSessionBool, use_trans_sid, php_ps_globals, ps_globals)
823840
PHP_INI_ENTRY("session.sid_length", "32", PHP_INI_ALL, OnUpdateSidLength)
824841
PHP_INI_ENTRY("session.sid_bits_per_character", "4", PHP_INI_ALL, OnUpdateSidBits)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
session_cache_expire() overflow
3+
--EXTENSIONS--
4+
session
5+
--SKIPIF--
6+
<?php include('skipif.inc'); ?>
7+
--FILE--
8+
<?php
9+
10+
ob_start();
11+
12+
echo "*** Testing session_cache_expire() : overflow test ***\n";
13+
14+
session_cache_limiter("public");
15+
var_dump(session_cache_expire(PHP_INT_MAX));
16+
session_start();
17+
var_dump(session_cache_expire() * 60);
18+
19+
echo "Done";
20+
ob_end_flush();
21+
?>
22+
--EXPECT--
23+
*** Testing session_cache_expire() : overflow test ***
24+
int(180)
25+
int(10800)
26+
Done
27+

0 commit comments

Comments
 (0)