Skip to content

Commit 245387a

Browse files
committed
Fix GH-16290: session cookie_lifetime ini value overflow.
1 parent a3eb1fd commit 245387a

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

ext/session/session.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,18 @@ static PHP_INI_MH(OnUpdateCookieLifetime) /* {{{ */
693693
{
694694
SESSION_CHECK_ACTIVE_STATE;
695695
SESSION_CHECK_OUTPUT_STATE;
696-
if (atol(ZSTR_VAL(new_value)) < 0) {
696+
697+
#ifdef ZEND_ENABLE_ZVAL_LONG64
698+
const zend_long maxcookie = ZEND_LONG_MAX - INT_MAX - 1;
699+
#else
700+
const zend_long maxcookie = ZEND_LONG_MAX / 2 - 1;
701+
#endif
702+
zend_long v = (zend_long)atol(ZSTR_VAL(new_value));
703+
if (v < 0) {
697704
php_error_docref(NULL, E_WARNING, "CookieLifetime cannot be negative");
698705
return FAILURE;
706+
} else if (v > maxcookie) {
707+
return SUCCESS;
699708
}
700709
return OnUpdateLongGEZero(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
701710
}

ext/session/tests/gh16290.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
GH-16290 (overflow on session cookie_lifetime ini)
3+
--EXTENSIONS--
4+
session
5+
--SKIPIF--
6+
<?php include('skipif.inc'); ?>
7+
--FILE--
8+
<?php
9+
session_set_cookie_params(PHP_INT_MAX, '/', null, false, true);
10+
echo "DONE";
11+
?>
12+
--EXPECT--
13+
DONE

ext/session/tests/session_set_cookie_params_variation8.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ bool(true)
2525
string(1) "0"
2626
string(1) "0"
2727

28-
Warning: session_set_cookie_params(): CookieLifetime cannot be negative in %s on line %d
28+
Warning: session_set_cookie_params(): CookieLifetime must be between %d and %d in %s on line %d
2929
bool(false)
3030
string(1) "0"
3131
Done

0 commit comments

Comments
 (0)