@@ -89,6 +89,21 @@ PHPAPI void php_register_known_variable(const char *var_name, size_t var_name_le
89
89
php_register_variable_quick (var_name , var_name_len , value , symbol_table );
90
90
}
91
91
92
+ /* Discard variable if mangling made it start with __Host-, where pre-mangling it did not start with __Host-
93
+ * Discard variable if mangling made it start with __Secure-, where pre-mangling it did not start with __Secure- */
94
+ static bool php_is_forbidden_variable_name (const char * mangled_name , size_t mangled_name_len , const char * pre_mangled_name )
95
+ {
96
+ if (mangled_name_len >= sizeof ("__Host-" )- 1 && strncmp (mangled_name , "__Host-" , sizeof ("__Host-" )- 1 ) == 0 && strncmp (pre_mangled_name , "__Host-" , sizeof ("__Host-" )- 1 ) != 0 ) {
97
+ return true;
98
+ }
99
+
100
+ if (mangled_name_len >= sizeof ("__Secure-" )- 1 && strncmp (mangled_name , "__Secure-" , sizeof ("__Secure-" )- 1 ) == 0 && strncmp (pre_mangled_name , "__Secure-" , sizeof ("__Secure-" )- 1 ) != 0 ) {
101
+ return true;
102
+ }
103
+
104
+ return false;
105
+ }
106
+
92
107
PHPAPI void php_register_variable_ex (const char * var_name , zval * val , zval * track_vars_array )
93
108
{
94
109
char * p = NULL ;
@@ -139,20 +154,6 @@ PHPAPI void php_register_variable_ex(const char *var_name, zval *val, zval *trac
139
154
}
140
155
var_len = p - var ;
141
156
142
- /* Discard variable if mangling made it start with __Host-, where pre-mangling it did not start with __Host- */
143
- if (strncmp (var , "__Host-" , sizeof ("__Host-" )- 1 ) == 0 && strncmp (var_name , "__Host-" , sizeof ("__Host-" )- 1 ) != 0 ) {
144
- zval_ptr_dtor_nogc (val );
145
- free_alloca (var_orig , use_heap );
146
- return ;
147
- }
148
-
149
- /* Discard variable if mangling made it start with __Secure-, where pre-mangling it did not start with __Secure- */
150
- if (strncmp (var , "__Secure-" , sizeof ("__Secure-" )- 1 ) == 0 && strncmp (var_name , "__Secure-" , sizeof ("__Secure-" )- 1 ) != 0 ) {
151
- zval_ptr_dtor_nogc (val );
152
- free_alloca (var_orig , use_heap );
153
- return ;
154
- }
155
-
156
157
if (var_len == 0 ) { /* empty variable name, or variable name with a space in it */
157
158
zval_ptr_dtor_nogc (val );
158
159
free_alloca (var_orig , use_heap );
@@ -256,6 +257,12 @@ PHPAPI void php_register_variable_ex(const char *var_name, zval *val, zval *trac
256
257
return ;
257
258
}
258
259
} else {
260
+ if (php_is_forbidden_variable_name (index , index_len , var_name )) {
261
+ zval_ptr_dtor_nogc (val );
262
+ free_alloca (var_orig , use_heap );
263
+ return ;
264
+ }
265
+
259
266
gpc_element_p = zend_symtable_str_find (symtable1 , index , index_len );
260
267
if (!gpc_element_p ) {
261
268
zval tmp ;
@@ -293,6 +300,12 @@ PHPAPI void php_register_variable_ex(const char *var_name, zval *val, zval *trac
293
300
zval_ptr_dtor_nogc (val );
294
301
}
295
302
} else {
303
+ if (php_is_forbidden_variable_name (index , index_len , var_name )) {
304
+ zval_ptr_dtor_nogc (val );
305
+ free_alloca (var_orig , use_heap );
306
+ return ;
307
+ }
308
+
296
309
zend_ulong idx ;
297
310
298
311
/*
0 commit comments