Skip to content

Commit 2f4a214

Browse files
authored
ext/standard: Reject null bytes in parse_str() (php#21942)
1 parent eba954d commit 2f4a214

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ PHP NEWS
191191
(Weilin Du)
192192
. getenv() and putenv() now raises a ValueError when the first argument
193193
contains null bytes. (Weilin Du)
194+
. parse_str() now raises a ValueError when the $string argument contains
195+
null bytes. (Weilin Du)
194196
. proc_open() now raises a ValueError when the $cwd argument contains
195197
null bytes. (Weilin Du)
196198

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ PHP 8.6 UPGRADE NOTES
9999
argument value is passed.
100100
. getenv() and putenv() now raises a ValueError when the first argument
101101
contains null bytes.
102+
. parse_str() now raises a ValueError when the $string argument contains
103+
null bytes.
102104
. linkinfo() now raises a ValueError when the $path argument is empty.
103105
. pathinfo() now raises a ValueError when an invalid $flag
104106
argument value is passed.

ext/standard/string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5012,7 +5012,7 @@ PHP_FUNCTION(parse_str)
50125012
size_t arglen;
50135013

50145014
ZEND_PARSE_PARAMETERS_START(2, 2)
5015-
Z_PARAM_STRING(arg, arglen)
5015+
Z_PARAM_PATH(arg, arglen)
50165016
Z_PARAM_ZVAL(arrayArg)
50175017
ZEND_PARSE_PARAMETERS_END();
50185018

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
parse_str() rejects null bytes
3+
--FILE--
4+
<?php
5+
6+
try {
7+
parse_str("a=1\0&b=2", $result);
8+
} catch (ValueError $e) {
9+
echo $e->getMessage(), "\n";
10+
}
11+
12+
?>
13+
--EXPECT--
14+
parse_str(): Argument #1 ($string) must not contain any null bytes

0 commit comments

Comments
 (0)