You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixed bug #70630 (Closure::call/bind() crash with ReflectionFunction->getClosure())
This additionally removes support for binding to an unknown (not in parent hierarchy) scope.
Removing support for cross-scope is necessary for certain compile-time assumptions (like class constants) to prevent unexpected results
zend_error(E_WARNING, "Cannot bind function %s::%s to object of class %s", ZSTR_VAL(closure->func.common.scope->name), ZSTR_VAL(closure->func.common.function_name), ZSTR_VAL(Z_OBJCE_P(newthis)->name));
102
104
return;
103
105
}
@@ -165,7 +167,7 @@ ZEND_METHOD(Closure, bind)
165
167
RETURN_NULL();
166
168
}
167
169
168
-
closure= (zend_closure*)Z_OBJ_P(zclosure);
170
+
closure= (zend_closure*)Z_OBJ_P(zclosure);
169
171
170
172
if ((newthis!=NULL) && (closure->func.common.fn_flags&ZEND_ACC_STATIC)) {
171
173
zend_error(E_WARNING, "Cannot bind an instance to a static closure");
zend_error(E_WARNING, "Cannot bind closure to scope of internal class %s", ZSTR_VAL(ce->name));
193
195
return;
@@ -202,6 +204,22 @@ ZEND_METHOD(Closure, bind)
202
204
called_scope=ce;
203
205
}
204
206
207
+
/* verify that we aren't binding methods to a wrong object */
208
+
if (closure->func.type!=ZEND_USER_FUNCTION|| (closure->func.common.fn_flags&ZEND_ACC_REAL_CLOSURE) ==0) {
209
+
if (!closure->func.common.scope) {
210
+
if (ce) {
211
+
zend_error(E_WARNING, "Cannot bind function %s to an object", ZSTR_VAL(closure->func.common.function_name));
212
+
return;
213
+
}
214
+
} elseif (!ce) {
215
+
zend_error(E_WARNING, "Cannot bind function %s::%s to no class", ZSTR_VAL(closure->func.common.scope->name), ZSTR_VAL(closure->func.common.function_name));
zend_error(E_WARNING, "Cannot bind function %s::%s to class %s", ZSTR_VAL(closure->func.common.scope->name), ZSTR_VAL(closure->func.common.function_name), ZSTR_VAL(ce->name));
zend_error(E_WARNING, "Cannot bind function %s::%s to object of class %s", ZSTR_VAL(func->common.scope->name), ZSTR_VAL(func->common.function_name), ZSTR_VAL(Z_OBJCE_P(this_ptr)->name));
563
580
scope=NULL;
564
-
this_ptr=NULL;
565
581
}
566
582
} else {
567
583
/* if it's a free function, we won't set scope & this since they're meaningless */
0 commit comments