Skip to content

Commit 84a8fea

Browse files
committed
Fix GH-16290: session cookie_lifetime ini value overflow.
close GH-16295
1 parent d94be24 commit 84a8fea

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ PHP NEWS
3535
- Session:
3636
. Fixed bug GH-16385 (Unexpected null returned by session_set_cookie_params).
3737
(nielsdos)
38+
. Fixed bug GH-16290 (overflow on cookie_lifetime ini value).
39+
(David Carlier)
3840

3941
- Sockets:
4042
. Fixed bug with overflow socket_recvfrom $length argument. (David Carlier)

ext/session/session.c

+10-1
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

+13
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_get_cookie_params_basic.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var_dump(session_get_cookie_params());
3535
echo "Done";
3636
ob_end_flush();
3737
?>
38-
--EXPECT--
38+
--EXPECTF--
3939
*** Testing session_get_cookie_params() : basic functionality ***
4040
array(6) {
4141
["lifetime"]=>
@@ -69,7 +69,7 @@ array(6) {
6969
bool(true)
7070
array(6) {
7171
["lifetime"]=>
72-
int(1234567890)
72+
int(%d)
7373
["path"]=>
7474
string(5) "/guff"
7575
["domain"]=>

0 commit comments

Comments
 (0)