Skip to content

Commit 49d3942

Browse files
committed
Fix GH-16290: session cookie_lifetime ini value overflow.
1 parent bf70d9b commit 49d3942

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

ext/session/session.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "ext/standard/php_var.h"
4141
#include "ext/date/php_date.h"
4242
#include "ext/standard/url_scanner_ex.h"
43+
#include "ext/standard/file.h"
4344
#include "ext/standard/info.h"
4445
#include "zend_smart_str.h"
4546
#include "ext/standard/url.h"
@@ -693,8 +694,11 @@ static PHP_INI_MH(OnUpdateCookieLifetime) /* {{{ */
693694
{
694695
SESSION_CHECK_ACTIVE_STATE;
695696
SESSION_CHECK_OUTPUT_STATE;
696-
if (atol(ZSTR_VAL(new_value)) < 0) {
697-
php_error_docref(NULL, E_WARNING, "CookieLifetime cannot be negative");
697+
698+
const zend_long maxcookie = ZEND_LONG_MAX - (PHP_TIMEOUT_ULL_MAX / 1000000);
699+
zend_long v = (zend_long)atol(ZSTR_VAL(new_value));
700+
if (v < 0 || v > maxcookie) {
701+
php_error_docref(NULL, E_WARNING, "CookieLifetime must be between 0 and " ZEND_LONG_FMT, maxcookie);
698702
return FAILURE;
699703
}
700704
return OnUpdateLongGEZero(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);

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 0 and %d in %s on line %d
2929
bool(false)
3030
string(1) "0"
3131
Done

0 commit comments

Comments
 (0)