@@ -65,6 +65,21 @@ static zend_always_inline void php_register_variable_quick(const char *name, siz
65
65
zend_string_release_ex (key , 0 );
66
66
}
67
67
68
+ /* Discard variable if mangling made it start with __Host-, where pre-mangling it did not start with __Host-
69
+ * Discard variable if mangling made it start with __Secure-, where pre-mangling it did not start with __Secure- */
70
+ static zend_bool php_is_forbidden_variable_name (const char * mangled_name , size_t mangled_name_len , const char * pre_mangled_name )
71
+ {
72
+ if (mangled_name_len >= sizeof ("__Host-" )- 1 && strncmp (mangled_name , "__Host-" , sizeof ("__Host-" )- 1 ) == 0 && strncmp (pre_mangled_name , "__Host-" , sizeof ("__Host-" )- 1 ) != 0 ) {
73
+ return 1 ;
74
+ }
75
+
76
+ if (mangled_name_len >= sizeof ("__Secure-" )- 1 && strncmp (mangled_name , "__Secure-" , sizeof ("__Secure-" )- 1 ) == 0 && strncmp (pre_mangled_name , "__Secure-" , sizeof ("__Secure-" )- 1 ) != 0 ) {
77
+ return 1 ;
78
+ }
79
+
80
+ return 0 ;
81
+ }
82
+
68
83
PHPAPI void php_register_variable_ex (char * var_name , zval * val , zval * track_vars_array )
69
84
{
70
85
char * p = NULL ;
@@ -115,20 +130,6 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars
115
130
}
116
131
var_len = p - var ;
117
132
118
- /* Discard variable if mangling made it start with __Host-, where pre-mangling it did not start with __Host- */
119
- if (strncmp (var , "__Host-" , sizeof ("__Host-" )- 1 ) == 0 && strncmp (var_name , "__Host-" , sizeof ("__Host-" )- 1 ) != 0 ) {
120
- zval_ptr_dtor_nogc (val );
121
- free_alloca (var_orig , use_heap );
122
- return ;
123
- }
124
-
125
- /* Discard variable if mangling made it start with __Secure-, where pre-mangling it did not start with __Secure- */
126
- if (strncmp (var , "__Secure-" , sizeof ("__Secure-" )- 1 ) == 0 && strncmp (var_name , "__Secure-" , sizeof ("__Secure-" )- 1 ) != 0 ) {
127
- zval_ptr_dtor_nogc (val );
128
- free_alloca (var_orig , use_heap );
129
- return ;
130
- }
131
-
132
133
if (var_len == 0 ) { /* empty variable name, or variable name with a space in it */
133
134
zval_ptr_dtor_nogc (val );
134
135
free_alloca (var_orig , use_heap );
@@ -226,6 +227,12 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars
226
227
return ;
227
228
}
228
229
} else {
230
+ if (php_is_forbidden_variable_name (index , index_len , var_name )) {
231
+ zval_ptr_dtor_nogc (val );
232
+ free_alloca (var_orig , use_heap );
233
+ return ;
234
+ }
235
+
229
236
gpc_element_p = zend_symtable_str_find (symtable1 , index , index_len );
230
237
if (!gpc_element_p ) {
231
238
zval tmp ;
@@ -263,6 +270,12 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars
263
270
zval_ptr_dtor_nogc (val );
264
271
}
265
272
} else {
273
+ if (php_is_forbidden_variable_name (index , index_len , var_name )) {
274
+ zval_ptr_dtor_nogc (val );
275
+ free_alloca (var_orig , use_heap );
276
+ return ;
277
+ }
278
+
266
279
zend_ulong idx ;
267
280
268
281
/*
0 commit comments