Skip to content

Commit 13104f1

Browse files
committed
set the upper boundary to 1 year max.
being generous adding 1 day for leap ones.
1 parent b651ca6 commit 13104f1

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

ext/session/session.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <sys/stat.h>
3232
#include <fcntl.h>
33+
#include <time.h>
3334

3435
#include "php_ini.h"
3536
#include "SAPI.h"
@@ -694,7 +695,17 @@ static PHP_INI_MH(OnUpdateCookieLifetime) /* {{{ */
694695
SESSION_CHECK_ACTIVE_STATE;
695696
SESSION_CHECK_OUTPUT_STATE;
696697

697-
const zend_long maxcookie = ZEND_LONG_MAX / 2 ;
698+
struct tm *tm, p;
699+
time_t n = time(NULL);
700+
zend_long maxcookie = 31536000 ;
701+
702+
tm = php_localtime_r(&n, &p);
703+
int y = tm->tm_year + 1900;
704+
705+
if (!(y % 4) || (!(y % 100) && !(y % 400))) {
706+
maxcookie += 86400;
707+
}
708+
698709
zend_long v = (zend_long)atol(ZSTR_VAL(new_value));
699710
if (v < 0 || v > maxcookie) {
700711
php_error_docref(NULL, E_WARNING, "CookieLifetime must be between 0 and " ZEND_LONG_FMT, maxcookie);

ext/session/tests/session_get_cookie_params_basic.phpt

Lines changed: 9 additions & 7 deletions
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"]=>
@@ -66,18 +66,20 @@ array(6) {
6666
["samesite"]=>
6767
string(0) ""
6868
}
69-
bool(true)
69+
70+
Warning: session_set_cookie_params(): CookieLifetime must be between 0 and %d in %s on line %d
71+
bool(false)
7072
array(6) {
7173
["lifetime"]=>
72-
int(1234567890)
74+
int(3600)
7375
["path"]=>
74-
string(5) "/guff"
76+
string(5) "/path"
7577
["domain"]=>
76-
string(3) "foo"
78+
string(4) "blah"
7779
["secure"]=>
78-
bool(true)
80+
bool(false)
7981
["httponly"]=>
80-
bool(true)
82+
bool(false)
8183
["samesite"]=>
8284
string(0) ""
8385
}

0 commit comments

Comments
 (0)