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 @@ -189,6 +189,8 @@ PHP NEWS
(Weilin Du)
. getenv() and putenv() now raises a ValueError when the first argument
contains null bytes. (Weilin Du)
. parse_str() now raises a ValueError when the $string argument contains
null bytes. (Weilin Du)
. proc_open() now raises a ValueError when the $cwd argument contains
null bytes. (Weilin Du)

Expand Down
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ PHP 8.6 UPGRADE NOTES
argument value is passed.
. getenv() and putenv() now raises a ValueError when the first argument
contains null bytes.
. parse_str() now raises a ValueError when the $string 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
2 changes: 1 addition & 1 deletion ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -5012,7 +5012,7 @@ PHP_FUNCTION(parse_str)
size_t arglen;

ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_STRING(arg, arglen)
Z_PARAM_PATH(arg, arglen)

This comment was marked as low quality.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the implementation of parse_str is based on C str, and therefore if the parsed string contains NUL bytes it will truncates the trailing part. Now, we have already done the same fix of getenv and putenv. From this fix we can throw a ValueError to users instead of silently truncate the input.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see, it would be great to add a comment here, that the limitation is due php_default_treat_data not supporting an explicit input string length.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Uh yes.That'd improve readability. Humm, we have lots of similar fix out there so adding comments to this case alone seems not to be effective... Could you please send a PR after this is merged to add this line of comment to every similar fix we have done before (i.e. reject NUL bytes because it silently truncates stuff)? Thank in advance!

Z_PARAM_ZVAL(arrayArg)
ZEND_PARSE_PARAMETERS_END();

Expand Down
14 changes: 14 additions & 0 deletions ext/standard/tests/strings/parse_str_null_bytes.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
parse_str() rejects null bytes
--FILE--
<?php

try {
parse_str("a=1\0&b=2", $result);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECT--
parse_str(): Argument #1 ($string) must not contain any null bytes
Loading