Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ PHP NEWS
argument value is passed. (Girgias)
. linkinfo() now raises a ValueError when the argument is an empty string.
(Weilin Du)
. getenv() and putenv() now raises a ValueError when the first argument
contains null bytes. (Weilin Du)

- Streams:
. Added so_keepalive, tcp_keepidle, tcp_keepintvl and tcp_keepcnt stream
Expand Down
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ PHP 8.6 UPGRADE NOTES
argument value is passed.
. array_change_key_case() now raises a ValueError when an invalid $case
argument value is passed.
. getenv() and putenv() now raises a ValueError when the first argument
contains null bytes.
. linkinfo() now raises a ValueError when the $path argument is empty.
. pathinfo() now raises a ValueError when an invalid $flag
argument value is passed.
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ PHP_FUNCTION(getenv)

ZEND_PARSE_PARAMETERS_START(0, 2)
Z_PARAM_OPTIONAL
Z_PARAM_STRING_OR_NULL(str, str_len)
Z_PARAM_PATH_OR_NULL(str, str_len)
Z_PARAM_BOOL(local_only)
ZEND_PARSE_PARAMETERS_END();

Expand Down Expand Up @@ -739,7 +739,7 @@ PHP_FUNCTION(putenv)
#endif

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(setting, setting_len)
Z_PARAM_PATH(setting, setting_len)
ZEND_PARSE_PARAMETERS_END();

if (setting_len == 0 || setting[0] == '=') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
getenv() and putenv() reject null bytes
--FILE--
<?php

foreach ([false, true] as $local_only) {
try {
getenv("PHP_GETENV_NUL_TEST\0SUFFIX", $local_only);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
}

$var_name = 'PHP_PUTENV_NUL_TEST';

foreach ([
$var_name . "\0SUFFIX=value",
$var_name . "=va\0lue",
] as $assignment) {
try {
putenv($assignment);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
}

var_dump(getenv($var_name));

?>
--EXPECT--
getenv(): Argument #1 ($name) must not contain any null bytes
getenv(): Argument #1 ($name) must not contain any null bytes
putenv(): Argument #1 ($assignment) must not contain any null bytes
putenv(): Argument #1 ($assignment) must not contain any null bytes
bool(false)