@@ -59,6 +59,21 @@ PHPAPI void php_register_variable_safe(char *var, char *strval, size_t str_len,
59
59
php_register_variable_ex (var , & new_entry , track_vars_array );
60
60
}
61
61
62
+ /* Discard variable if mangling made it start with __Host-, where pre-mangling it did not start with __Host-
63
+ * Discard variable if mangling made it start with __Secure-, where pre-mangling it did not start with __Secure- */
64
+ static zend_bool php_is_forbidden_variable_name (const char * mangled_name , size_t mangled_name_len , const char * pre_mangled_name )
65
+ {
66
+ if (mangled_name_len >= sizeof ("__Host-" )- 1 && strncmp (mangled_name , "__Host-" , sizeof ("__Host-" )- 1 ) == 0 && strncmp (pre_mangled_name , "__Host-" , sizeof ("__Host-" )- 1 ) != 0 ) {
67
+ return 1 ;
68
+ }
69
+
70
+ if (mangled_name_len >= sizeof ("__Secure-" )- 1 && strncmp (mangled_name , "__Secure-" , sizeof ("__Secure-" )- 1 ) == 0 && strncmp (pre_mangled_name , "__Secure-" , sizeof ("__Secure-" )- 1 ) != 0 ) {
71
+ return 1 ;
72
+ }
73
+
74
+ return 0 ;
75
+ }
76
+
62
77
PHPAPI void php_register_variable_ex (char * var_name , zval * val , zval * track_vars_array )
63
78
{
64
79
char * p = NULL ;
@@ -109,20 +124,6 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars
109
124
}
110
125
var_len = p - var ;
111
126
112
- /* Discard variable if mangling made it start with __Host-, where pre-mangling it did not start with __Host- */
113
- if (strncmp (var , "__Host-" , sizeof ("__Host-" )- 1 ) == 0 && strncmp (var_name , "__Host-" , sizeof ("__Host-" )- 1 ) != 0 ) {
114
- zval_ptr_dtor_nogc (val );
115
- free_alloca (var_orig , use_heap );
116
- return ;
117
- }
118
-
119
- /* Discard variable if mangling made it start with __Secure-, where pre-mangling it did not start with __Secure- */
120
- if (strncmp (var , "__Secure-" , sizeof ("__Secure-" )- 1 ) == 0 && strncmp (var_name , "__Secure-" , sizeof ("__Secure-" )- 1 ) != 0 ) {
121
- zval_ptr_dtor_nogc (val );
122
- free_alloca (var_orig , use_heap );
123
- return ;
124
- }
125
-
126
127
if (var_len == 0 ) { /* empty variable name, or variable name with a space in it */
127
128
zval_dtor (val );
128
129
free_alloca (var_orig , use_heap );
@@ -220,6 +221,12 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars
220
221
return ;
221
222
}
222
223
} else {
224
+ if (php_is_forbidden_variable_name (index , index_len , var_name )) {
225
+ zval_ptr_dtor_nogc (val );
226
+ free_alloca (var_orig , use_heap );
227
+ return ;
228
+ }
229
+
223
230
gpc_element_p = zend_symtable_str_find (symtable1 , index , index_len );
224
231
if (!gpc_element_p ) {
225
232
zval tmp ;
@@ -258,6 +265,12 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars
258
265
zval_ptr_dtor (& gpc_element );
259
266
}
260
267
} else {
268
+ if (php_is_forbidden_variable_name (index , index_len , var_name )) {
269
+ zval_ptr_dtor_nogc (val );
270
+ free_alloca (var_orig , use_heap );
271
+ return ;
272
+ }
273
+
261
274
/*
262
275
* According to rfc2965, more specific paths are listed above the less specific ones.
263
276
* If we encounter a duplicate cookie name, we should skip it, since it is not possible
0 commit comments