File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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() now raises a ValueError when the $name argument contains null
174+ bytes. (Weilin Du)
173175 . putenv() now raises a ValueError when the $assignment argument contains
174176 null bytes. (Weilin Du)
175177
Original file line number Diff line number Diff 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() now raises a ValueError when the $name argument contains null
92+ bytes.
9193 . putenv() now raises a ValueError when the $assignment argument contains
9294 null bytes.
9395 . linkinfo() now raises a ValueError when the $path argument is empty.
Original file line number Diff line number Diff line change @@ -706,6 +706,11 @@ PHP_FUNCTION(getenv)
706706 return ;
707707 }
708708
709+ if (UNEXPECTED (memchr (str , '\0' , str_len ) != NULL )) {
710+ zend_argument_value_error (1 , "must not contain any null bytes" );
711+ RETURN_THROWS ();
712+ }
713+
709714 if (!local_only ) {
710715 /* SAPI method returns an emalloc()'d string */
711716 char * ptr = sapi_getenv (str , str_len );
@@ -742,7 +747,7 @@ PHP_FUNCTION(putenv)
742747 Z_PARAM_STRING (setting , setting_len )
743748 ZEND_PARSE_PARAMETERS_END ();
744749
745- if (memchr (setting , '\0' , setting_len ) != NULL ) {
750+ if (UNEXPECTED ( memchr (setting , '\0' , setting_len ) != NULL ) ) {
746751 zend_argument_value_error (1 , "must not contain any null bytes" );
747752 RETURN_THROWS ();
748753 }
Original file line number Diff line number Diff line change 1+ --TEST--
2+ getenv() rejects 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+ ?>
15+ --EXPECT--
16+ getenv(): Argument #1 ($name) must not contain any null bytes
17+ getenv(): Argument #1 ($name) must not contain any null bytes
You can’t perform that action at this time.
0 commit comments