Skip to content

Commit 0b76b81

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

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

ext/session/session.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,11 @@ static PHP_INI_MH(OnUpdateCookieLifetime) /* {{{ */
693693
{
694694
SESSION_CHECK_ACTIVE_STATE;
695695
SESSION_CHECK_OUTPUT_STATE;
696-
if (atol(ZSTR_VAL(new_value)) < 0) {
697-
php_error_docref(NULL, E_WARNING, "CookieLifetime cannot be negative");
696+
697+
const zend_long maxcookie = ZEND_LONG_MAX > INT_MAX ? ZEND_LONG_MAX - INT_MAX - 1: INT_MAX - 1;
698+
zend_long v = (zend_long)atol(ZSTR_VAL(new_value));
699+
if (v < 0 || v > maxcookie) {
700+
php_error_docref(NULL, E_WARNING, "CookieLifetime must be between 0 and " ZEND_LONG_FMT, maxcookie);
698701
return FAILURE;
699702
}
700703
return OnUpdateLongGEZero(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);

ext/session/tests/gh16290.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
?>
11+
--EXPECTF--
12+
Warning: session_set_cookie_params(): CookieLifetime must be between 0 and %d in %s on line %d

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)