Skip to content

Commit

Permalink
Fix GH-16385: Unexpected null returned by session_set_cookie_params
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nielsdos committed Oct 12, 2024
1 parent e8ef81a commit 7cdd130
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ PHP NEWS
- PHPDBG:
. Fixed bug GH-16174 (Empty string is an invalid expression for ev). (cmb)

- Session:
. Fixed bug GH-16385 (Unexpected null returned by session_set_cookie_params).
(nielsdos)

- XMLReader:
. Fixed bug GH-16292 (Segmentation fault in ext/xmlreader/php_xmlreader.c).
(nielsdos)
Expand Down
9 changes: 5 additions & 4 deletions ext/session/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -1668,10 +1668,6 @@ PHP_FUNCTION(session_set_cookie_params)
zend_result result;
int found = 0;

if (!PS(use_cookies)) {
return;
}

ZEND_PARSE_PARAMETERS_START(1, 5)
Z_PARAM_ARRAY_HT_OR_LONG(options_ht, lifetime_long)
Z_PARAM_OPTIONAL
Expand All @@ -1681,6 +1677,11 @@ PHP_FUNCTION(session_set_cookie_params)
Z_PARAM_BOOL_OR_NULL(httponly, httponly_null)
ZEND_PARSE_PARAMETERS_END();

if (!PS(use_cookies)) {
php_error_docref(NULL, E_WARNING, "Session cookies cannot be used when session.use_cookies is disabled");
RETURN_FALSE;
}

if (PS(session_status) == php_session_active) {
php_error_docref(NULL, E_WARNING, "Session cookie parameters cannot be changed when a session is active");
RETURN_FALSE;
Expand Down
13 changes: 13 additions & 0 deletions ext/session/tests/gh16385.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
GH-16385 (Unexpected null returned by session_set_cookie_params)
--EXTENSIONS--
session
--INI--
session.use_cookies=0
--FILE--
<?php
var_dump(session_set_cookie_params(3600, "/foo"));
?>
--EXPECTF--
Warning: session_set_cookie_params(): Session cookies cannot be used when session.use_cookies is disabled in %s on line %d
bool(false)

0 comments on commit 7cdd130

Please sign in to comment.