Skip to content

Commit c332950

Browse files
derickrsgolemon
authored andcommitted
Fix #81727: Don't mangle HTTP variable names that clash with ones that have a specific semantic meaning.
1 parent c34b452 commit c332950

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

ext/standard/tests/bug81727.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #81727: $_COOKIE name starting with ..Host/..Secure should be discarded
3+
--COOKIE--
4+
..Host-test=ignore; __Host-test=correct; . Secure-test=ignore; . Elephpant=Awesome;
5+
--FILE--
6+
<?php
7+
var_dump($_COOKIE);
8+
?>
9+
--EXPECT--
10+
array(2) {
11+
["__Host-test"]=>
12+
string(7) "correct"
13+
["__Elephpant"]=>
14+
string(7) "Awesome"
15+
}

main/php_variables.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@ PHPAPI void php_register_variable_ex(const char *var_name, zval *val, zval *trac
104104
}
105105
var_len = p - var;
106106

107+
/* Discard variable if mangling made it start with __Host-, where pre-mangling it did not start with __Host- */
108+
if (strncmp(var, "__Host-", sizeof("__Host-")-1) == 0 && strncmp(var_name, "__Host-", sizeof("__Host-")-1) != 0) {
109+
zval_ptr_dtor_nogc(val);
110+
free_alloca(var_orig, use_heap);
111+
return;
112+
}
113+
114+
/* Discard variable if mangling made it start with __Secure-, where pre-mangling it did not start with __Secure- */
115+
if (strncmp(var, "__Secure-", sizeof("__Secure-")-1) == 0 && strncmp(var_name, "__Secure-", sizeof("__Secure-")-1) != 0) {
116+
zval_ptr_dtor_nogc(val);
117+
free_alloca(var_orig, use_heap);
118+
return;
119+
}
120+
107121
if (var_len==0) { /* empty variable name, or variable name with a space in it */
108122
zval_ptr_dtor_nogc(val);
109123
free_alloca(var_orig, use_heap);

0 commit comments

Comments
 (0)