Skip to content

Commit b7ba070

Browse files
committed
ext/standard: throw ValueError if argument contains null byte in session_module_name()
And fix error message to use 'must not' rather than 'cannot'
1 parent 6f469cb commit b7ba070

4 files changed

Lines changed: 30 additions & 5 deletions

File tree

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ PHP 8.6 UPGRADE NOTES
2323
. Invalid values now throw in Phar::mungServer() instead of being silently
2424
ignored.
2525

26+
- Session:
27+
. A ValueError is not thrown if $name is a string containing null bytes in
28+
session_module_name().
29+
2630
- Standard:
2731
. Invalid mode values now throw in array_filter() instead of being silently
2832
defaulted to 0.

ext/session/session.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,9 +1996,8 @@ PHP_FUNCTION(session_name)
19961996
PHP_FUNCTION(session_module_name)
19971997
{
19981998
zend_string *name = NULL;
1999-
zend_string *ini_name;
20001999

2001-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!", &name) == FAILURE) {
2000+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|P!", &name) == FAILURE) {
20022001
RETURN_THROWS();
20032002
}
20042003

@@ -2015,7 +2014,7 @@ PHP_FUNCTION(session_module_name)
20152014

20162015
if (name) {
20172016
if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_USER))) {
2018-
zend_argument_value_error(1, "cannot be \"user\"");
2017+
zend_argument_value_error(1, "must not be \"user\"");
20192018
RETURN_THROWS();
20202019
}
20212020
if (!_php_find_ps_module(ZSTR_VAL(name))) {
@@ -2029,7 +2028,7 @@ PHP_FUNCTION(session_module_name)
20292028
}
20302029
PS(mod_data) = NULL;
20312030

2032-
ini_name = ZSTR_INIT_LITERAL("session.save_handler", false);
2031+
zend_string *ini_name = ZSTR_INIT_LITERAL("session.save_handler", false);
20332032
zend_alter_ini_entry(ini_name, name, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
20342033
zend_string_release_ex(ini_name, false);
20352034
}

ext/session/tests/bug73100.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ bool(true)
2424

2525
Warning: session_module_name(): Session save handler module cannot be changed when a session is active (started from %s on line %d) in %s on line %d
2626
bool(true)
27-
session_module_name(): Argument #1 ($module) cannot be "user"
27+
session_module_name(): Argument #1 ($module) must not be "user"
2828
===DONE===
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
session_module_name(): errors
3+
--EXTENSIONS--
4+
session
5+
--FILE--
6+
<?php
7+
8+
try {
9+
var_dump(session_module_name("user"));
10+
} catch (Throwable $e) {
11+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
12+
}
13+
try {
14+
var_dump(session_module_name("fi\0le"));
15+
} catch (Throwable $e) {
16+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
17+
}
18+
19+
?>
20+
--EXPECT--
21+
ValueError: session_module_name(): Argument #1 ($module) must not be "user"
22+
ValueError: session_module_name(): Argument #1 ($module) must not contain any null bytes

0 commit comments

Comments
 (0)