@@ -54,6 +54,21 @@ static zend_always_inline void php_register_variable_quick(const char *name, siz
54
54
zend_string_release_ex (key , 0 );
55
55
}
56
56
57
+ /* Discard variable if mangling made it start with __Host-, where pre-mangling it did not start with __Host-
58
+ * Discard variable if mangling made it start with __Secure-, where pre-mangling it did not start with __Secure- */
59
+ static bool php_is_forbidden_variable_name (const char * mangled_name , size_t mangled_name_len , const char * pre_mangled_name )
60
+ {
61
+ if (mangled_name_len >= sizeof ("__Host-" )- 1 && strncmp (mangled_name , "__Host-" , sizeof ("__Host-" )- 1 ) == 0 && strncmp (pre_mangled_name , "__Host-" , sizeof ("__Host-" )- 1 ) != 0 ) {
62
+ return true;
63
+ }
64
+
65
+ if (mangled_name_len >= sizeof ("__Secure-" )- 1 && strncmp (mangled_name , "__Secure-" , sizeof ("__Secure-" )- 1 ) == 0 && strncmp (pre_mangled_name , "__Secure-" , sizeof ("__Secure-" )- 1 ) != 0 ) {
66
+ return true;
67
+ }
68
+
69
+ return false;
70
+ }
71
+
57
72
PHPAPI void php_register_variable_ex (const char * var_name , zval * val , zval * track_vars_array )
58
73
{
59
74
char * p = NULL ;
@@ -104,20 +119,6 @@ PHPAPI void php_register_variable_ex(const char *var_name, zval *val, zval *trac
104
119
}
105
120
var_len = p - var ;
106
121
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
-
121
122
if (var_len == 0 ) { /* empty variable name, or variable name with a space in it */
122
123
zval_ptr_dtor_nogc (val );
123
124
free_alloca (var_orig , use_heap );
@@ -221,6 +222,12 @@ PHPAPI void php_register_variable_ex(const char *var_name, zval *val, zval *trac
221
222
return ;
222
223
}
223
224
} else {
225
+ if (php_is_forbidden_variable_name (index , index_len , var_name )) {
226
+ zval_ptr_dtor_nogc (val );
227
+ free_alloca (var_orig , use_heap );
228
+ return ;
229
+ }
230
+
224
231
gpc_element_p = zend_symtable_str_find (symtable1 , index , index_len );
225
232
if (!gpc_element_p ) {
226
233
zval tmp ;
@@ -258,6 +265,12 @@ PHPAPI void php_register_variable_ex(const char *var_name, zval *val, zval *trac
258
265
zval_ptr_dtor_nogc (val );
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
zend_ulong idx ;
262
275
263
276
/*
0 commit comments