Skip to content

Throw a ValueError when the parameter includes NUL bytes in putenv and getenv#21817

Merged
Girgias merged 7 commits intophp:masterfrom
LamentXU123:bug-fix
Apr 21, 2026
Merged

Throw a ValueError when the parameter includes NUL bytes in putenv and getenv#21817
Girgias merged 7 commits intophp:masterfrom
LamentXU123:bug-fix

Conversation

@LamentXU123
Copy link
Copy Markdown
Contributor

@LamentXU123 LamentXU123 commented Apr 21, 2026

Currently string in putenv and getenv can be truncated by NUL:

<?php
var_dump(putenv("PHP_PUTENV_NUL_TEST=va\0ue"));
echo getenv('PHP_PUTENV_NUL_TEST');
echo getenv("PHP_PUTENV_NUL_TEST\0asd");

output:

bool(true)
vava

Reproduce in https://3v4l.org/ngSWJ
According to the newest policy these cases are supposed to resulted in a ValueError.

@LamentXU123 LamentXU123 changed the title Throw a ValueError when the parameter includes NUL bytes in putenv Throw a ValueError when the parameter includes NUL bytes in putenv and getenv Apr 21, 2026
Comment thread ext/standard/basic_functions.c Outdated
Comment thread NEWS Outdated
argument value is passed. (Girgias)
. linkinfo() now raises a ValueError when the argument is an empty string.
(Weilin Du)
. getenv() now raises a ValueError when the $name argument contains null
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think getenv()/putenv() entries can be crammed into one wdyt ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah indeed, a single entry is probably easier.

Copy link
Copy Markdown
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Minor nit about the NEWS/UPGRADING entry but lgtm otherwise :)

Comment thread NEWS Outdated
argument value is passed. (Girgias)
. linkinfo() now raises a ValueError when the argument is an empty string.
(Weilin Du)
. getenv() now raises a ValueError when the $name argument contains null
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah indeed, a single entry is probably easier.

@LamentXU123
Copy link
Copy Markdown
Contributor Author

LamentXU123 commented Apr 21, 2026

Fixed :) Not that much sure if the wording here is proper. I use the first argument to refer to $name and $assignment arguments in both functions. (getenv has 2 arguments that could be passed but putenv only has 1)

@Girgias Girgias merged commit 701d8a6 into php:master Apr 21, 2026
1 of 2 checks passed
jordikroon added a commit to jordikroon/php-src that referenced this pull request Apr 21, 2026
* master: (26 commits)
  Fix usage of optimize attribute on unsupported compilers (phpGH-21819)
  PHP 8.4 is now for PHP 8.4.22-dev
  ext/phar: remove `phar_archive_data->alias == phar_archive_data->fname` checks (php#21820)
  [skip ci] Mark curl/bug71523.phpt as online test
  [skip ci] Sort paths-ignore and remove cirrus
  [skip ci] Tweak paths-ignore
  ext/standard: Throw a ValueError when the parameter includes NUL bytes in `putenv` and `getenv` (php#21817)
  ext/session: fix missing zval_ptr_dtor for retval in PS_GC_FUNC(user)
  [skip ci] Backport CI changes
  ext/gmp: reject values larger than unsigned long in gmp_pow/binomial/root/rootrem and shift/pow operators.
  Update NEWS for recent bug fixes
  ext/phar: Fix memory leak in phar_verify_signature() when md_ctx is invalid
  phar: propagate phar_stream_flush return value from phar_stream_close
  phar: call phar_entry_delref before goto finish in phar_add_file error paths
  phar: free is_temp_dir entry before rejecting .phar/* paths in offsetGet
  phar: fix NULL dereference in Phar::webPhar() when SCRIPT_NAME is absent
  phar: restore is_link handler in phar_intercept_functions_shutdown
  ext/session: improve parsing of session.cookie_lifetime (php#21704)
  /ext/standard: Check for empty string in linkinfo() (php#21793)
  [Windows] Improve clang-cl support (php#21618)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants