Skip to content

Commit 7cdd130

Browse files
committed
Fix GH-16385: Unexpected null returned by session_set_cookie_params
Two issues: 1) The check happened before ZPP checks 2) The `return;` statement caused NULL to be returned while this function can only return booleans. An exception seems not acceptable in stable versions, but a warning may do. Closes GH-16386.
1 parent e8ef81a commit 7cdd130

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ PHP NEWS
2828
- PHPDBG:
2929
. Fixed bug GH-16174 (Empty string is an invalid expression for ev). (cmb)
3030

31+
- Session:
32+
. Fixed bug GH-16385 (Unexpected null returned by session_set_cookie_params).
33+
(nielsdos)
34+
3135
- XMLReader:
3236
. Fixed bug GH-16292 (Segmentation fault in ext/xmlreader/php_xmlreader.c).
3337
(nielsdos)

ext/session/session.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,10 +1668,6 @@ PHP_FUNCTION(session_set_cookie_params)
16681668
zend_result result;
16691669
int found = 0;
16701670

1671-
if (!PS(use_cookies)) {
1672-
return;
1673-
}
1674-
16751671
ZEND_PARSE_PARAMETERS_START(1, 5)
16761672
Z_PARAM_ARRAY_HT_OR_LONG(options_ht, lifetime_long)
16771673
Z_PARAM_OPTIONAL
@@ -1681,6 +1677,11 @@ PHP_FUNCTION(session_set_cookie_params)
16811677
Z_PARAM_BOOL_OR_NULL(httponly, httponly_null)
16821678
ZEND_PARSE_PARAMETERS_END();
16831679

1680+
if (!PS(use_cookies)) {
1681+
php_error_docref(NULL, E_WARNING, "Session cookies cannot be used when session.use_cookies is disabled");
1682+
RETURN_FALSE;
1683+
}
1684+
16841685
if (PS(session_status) == php_session_active) {
16851686
php_error_docref(NULL, E_WARNING, "Session cookie parameters cannot be changed when a session is active");
16861687
RETURN_FALSE;

ext/session/tests/gh16385.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
GH-16385 (Unexpected null returned by session_set_cookie_params)
3+
--EXTENSIONS--
4+
session
5+
--INI--
6+
session.use_cookies=0
7+
--FILE--
8+
<?php
9+
var_dump(session_set_cookie_params(3600, "/foo"));
10+
?>
11+
--EXPECTF--
12+
Warning: session_set_cookie_params(): Session cookies cannot be used when session.use_cookies is disabled in %s on line %d
13+
bool(false)

0 commit comments

Comments
 (0)