Skip to content

Commit 01d78ec

Browse files
committed
Merge remote-tracking branch 'upstream/master' into feat/clang-windows-tailcall
2 parents 4b35586 + 701d8a6 commit 01d78ec

6 files changed

Lines changed: 75 additions & 2 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ PHP NEWS
170170
argument value is passed. (Girgias)
171171
. linkinfo() now raises a ValueError when the argument is an empty string.
172172
(Weilin Du)
173+
. getenv() and putenv() now raises a ValueError when the first argument
174+
contains null bytes. (Weilin Du)
173175

174176
- Streams:
175177
. Added so_keepalive, tcp_keepidle, tcp_keepintvl and tcp_keepcnt stream

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ PHP 8.6 UPGRADE NOTES
8888
argument value is passed.
8989
. array_change_key_case() now raises a ValueError when an invalid $case
9090
argument value is passed.
91+
. getenv() and putenv() now raises a ValueError when the first argument
92+
contains null bytes.
9193
. linkinfo() now raises a ValueError when the $path argument is empty.
9294
. pathinfo() now raises a ValueError when an invalid $flag
9395
argument value is passed.

ext/session/mod_user.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ PS_GC_FUNC(user)
214214
/* Anything else is some kind of error */
215215
*nrdels = -1; // Error
216216
}
217+
zval_ptr_dtor(&retval);
217218
return *nrdels;
218219
}
219220

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
session_gc(): user handler returning non-bool/non-int does not leak memory
3+
--INI--
4+
session.gc_probability=0
5+
session.save_handler=files
6+
--EXTENSIONS--
7+
session
8+
--FILE--
9+
<?php
10+
ob_start();
11+
12+
// Procedural API has no return type enforcement, so gc can return a string
13+
// (reference-counted), which PS_GC_FUNC(user) previously did not free.
14+
session_set_save_handler(
15+
function(string $path, string $name) { return true; },
16+
function() { return true; },
17+
function(string $id): string|false { return ""; },
18+
function(string $id, string $data) { return true; },
19+
function(string $id) { return true; },
20+
function(int $max) { return str_repeat("x", random_int(100, 100)); }
21+
);
22+
23+
session_start();
24+
$result = session_gc();
25+
var_dump($result);
26+
session_write_close();
27+
28+
ob_end_flush();
29+
?>
30+
--EXPECTF--
31+
32+
Deprecated: session_set_save_handler(): Providing individual callbacks instead of an object implementing SessionHandlerInterface is deprecated in %s on line %d
33+
bool(false)

ext/standard/basic_functions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ PHP_FUNCTION(getenv)
696696

697697
ZEND_PARSE_PARAMETERS_START(0, 2)
698698
Z_PARAM_OPTIONAL
699-
Z_PARAM_STRING_OR_NULL(str, str_len)
699+
Z_PARAM_PATH_OR_NULL(str, str_len)
700700
Z_PARAM_BOOL(local_only)
701701
ZEND_PARSE_PARAMETERS_END();
702702

@@ -739,7 +739,7 @@ PHP_FUNCTION(putenv)
739739
#endif
740740

741741
ZEND_PARSE_PARAMETERS_START(1, 1)
742-
Z_PARAM_STRING(setting, setting_len)
742+
Z_PARAM_PATH(setting, setting_len)
743743
ZEND_PARSE_PARAMETERS_END();
744744

745745
if (setting_len == 0 || setting[0] == '=') {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
getenv() and putenv() reject null bytes
3+
--FILE--
4+
<?php
5+
6+
foreach ([false, true] as $local_only) {
7+
try {
8+
getenv("PHP_GETENV_NUL_TEST\0SUFFIX", $local_only);
9+
} catch (ValueError $exception) {
10+
echo $exception->getMessage() . "\n";
11+
}
12+
}
13+
14+
$var_name = 'PHP_PUTENV_NUL_TEST';
15+
16+
foreach ([
17+
$var_name . "\0SUFFIX=value",
18+
$var_name . "=va\0lue",
19+
] as $assignment) {
20+
try {
21+
putenv($assignment);
22+
} catch (ValueError $exception) {
23+
echo $exception->getMessage() . "\n";
24+
}
25+
}
26+
27+
var_dump(getenv($var_name));
28+
29+
?>
30+
--EXPECT--
31+
getenv(): Argument #1 ($name) must not contain any null bytes
32+
getenv(): Argument #1 ($name) must not contain any null bytes
33+
putenv(): Argument #1 ($assignment) must not contain any null bytes
34+
putenv(): Argument #1 ($assignment) must not contain any null bytes
35+
bool(false)

0 commit comments

Comments
 (0)