Skip to content

Commit fc4d462

Browse files
committed
Fix #78236: convert error on receiving variables when duplicate [
When an input variable name contains a non matched open bracket, we not only have to replace that with an underscore, but also all following forbidden characters.
1 parent 4293dd5 commit fc4d462

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.0.0beta1
44

5+
- Core:
6+
. Fixed bug #78236 (convert error on receiving variables when duplicate [).
7+
(cmb)
8+
59
- JIT:
610
. Fixed bug #79864 (JIT segfault in Symfony OptionsResolver). (Dmitry)
711

main/php_variables.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,14 @@ PHPAPI void php_register_variable_ex(const char *var_name, zval *val, zval *trac
178178
} else {
179179
ip = strchr(ip, ']');
180180
if (!ip) {
181-
/* PHP variables cannot contain '[' in their names, so we replace the character with a '_' */
181+
/* not an index; un-terminate the var name */
182182
*(index_s - 1) = '_';
183+
/* PHP variables cannot contain ' ', '.', '[' in their names, so we replace the characters with a '_' */
184+
for (p = index_s; *p; p++) {
185+
if (*p == ' ' || *p == '.' || *p == '[') {
186+
*p = '_';
187+
}
188+
}
183189

184190
index_len = 0;
185191
if (index) {

tests/basic/bug78236.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #78236 (convert error on receiving variables when duplicate [)
3+
--POST--
4+
id[name=1&id[[name=a&id[na me.=3
5+
--FILE--
6+
<?php
7+
var_dump($_POST);
8+
?>
9+
--EXPECT--
10+
array(3) {
11+
["id_name"]=>
12+
string(1) "1"
13+
["id__name"]=>
14+
string(1) "a"
15+
["id_na_me_"]=>
16+
string(1) "3"
17+
}

0 commit comments

Comments
 (0)