Skip to content

Commit ad28dd8

Browse files
committed
Fix default value handling of session_set_cookie_params()
1 parent 3a6fe10 commit ad28dd8

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

ext/session/session.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,10 +1681,10 @@ PHP_FUNCTION(session_set_cookie_params)
16811681
ZEND_PARSE_PARAMETERS_START(1, 5)
16821682
Z_PARAM_ARRAY_HT_OR_LONG(options_ht, lifetime_long)
16831683
Z_PARAM_OPTIONAL
1684-
Z_PARAM_STR(path)
1685-
Z_PARAM_STR(domain)
1686-
Z_PARAM_BOOL_EX(secure, secure_null, 1, 0)
1687-
Z_PARAM_BOOL_EX(httponly, httponly_null, 1, 0)
1684+
Z_PARAM_STR_OR_NULL(path)
1685+
Z_PARAM_STR_OR_NULL(domain)
1686+
Z_PARAM_BOOL_OR_NULL(secure, secure_null)
1687+
Z_PARAM_BOOL_OR_NULL(httponly, httponly_null)
16881688
ZEND_PARSE_PARAMETERS_END();
16891689

16901690
if (PS(session_status) == php_session_active) {
@@ -1702,12 +1702,23 @@ PHP_FUNCTION(session_set_cookie_params)
17021702
zval *value;
17031703

17041704
if (path) {
1705-
path = NULL;
1706-
domain = NULL;
1707-
secure_null = 1;
1708-
httponly_null = 1;
1709-
php_error_docref(NULL, E_WARNING, "Cannot pass arguments after the options array");
1710-
RETURN_FALSE;
1705+
zend_argument_value_error(2, "must be null when argument #1 ($lifetime_or_options) is an array");
1706+
RETURN_THROWS();
1707+
}
1708+
1709+
if (domain) {
1710+
zend_argument_value_error(3, "must be null when argument #1 ($lifetime_or_options) is an array");
1711+
RETURN_THROWS();
1712+
}
1713+
1714+
if (!secure_null) {
1715+
zend_argument_value_error(4, "must be null when argument #1 ($lifetime_or_options) is an array");
1716+
RETURN_THROWS();
1717+
}
1718+
1719+
if (!httponly_null) {
1720+
zend_argument_value_error(5, "must be null when argument #1 ($lifetime_or_options) is an array");
1721+
RETURN_THROWS();
17111722
}
17121723

17131724
ZEND_HASH_FOREACH_STR_KEY_VAL(options_ht, key, value) {

ext/session/session.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function session_cache_limiter(?string $cache_limiter = null): string|false {}
5656

5757
function session_cache_expire(?int $new_cache_expire = null): int|false {}
5858

59-
function session_set_cookie_params(array|int $lifetime_or_options, string $path = UNKNOWN, string $domain = "", ?bool $secure = null, ?bool $httponly = null): bool {}
59+
function session_set_cookie_params(array|int $lifetime_or_options, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httponly = null): bool {}
6060

6161
function session_start(array $options = []): bool {}
6262

ext/session/session_arginfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 65cb39f0e137377df2a14157926b109be3dcc951 */
2+
* Stub hash: 77c4527f6ad12298f226206d8afcea60c4086329 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_session_name, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, name, IS_STRING, 1, "null")
@@ -79,8 +79,8 @@ ZEND_END_ARG_INFO()
7979

8080
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_session_set_cookie_params, 0, 1, _IS_BOOL, 0)
8181
ZEND_ARG_TYPE_MASK(0, lifetime_or_options, MAY_BE_ARRAY|MAY_BE_LONG, NULL)
82-
ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0)
83-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, domain, IS_STRING, 0, "\"\"")
82+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, path, IS_STRING, 1, "null")
83+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, domain, IS_STRING, 1, "null")
8484
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, secure, _IS_BOOL, 1, "null")
8585
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, httponly, _IS_BOOL, 1, "null")
8686
ZEND_END_ARG_INFO()

ext/session/tests/session_set_cookie_params_variation7.phpt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ var_dump(session_set_cookie_params(["lifetime" => 42]));
3131
var_dump(ini_get("session.cookie_lifetime"));
3232

3333
var_dump(ini_get("session.cookie_path"));
34-
var_dump(session_set_cookie_params(["path" => "newpath/"], "arg after options array"));
34+
35+
try {
36+
session_set_cookie_params(["path" => "newpath/"], "arg after options array");
37+
} catch (ValueError $exception) {
38+
echo $exception->getMessage() . "\n";
39+
}
40+
3541
var_dump(ini_get("session.cookie_path"));
3642

3743
echo "Done";
@@ -58,8 +64,6 @@ string(1) "0"
5864
bool(true)
5965
string(2) "42"
6066
string(1) "/"
61-
62-
Warning: session_set_cookie_params(): Cannot pass arguments after the options array in %s
63-
bool(false)
67+
session_set_cookie_params(): Argument #2 ($path) must be null when argument #1 ($lifetime_or_options) is an array
6468
string(1) "/"
6569
Done

0 commit comments

Comments
 (0)