diff --git a/NEWS b/NEWS index 5cf236fb2b7..4d2b9ba8c41 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,8 @@ PHP NEWS getClosure()). (Dmitry, Bob) . Fixed bug #70662 (Duplicate array key via undefined index error handler). (Nikita) + . Fixed buf #70681 (Segfault when binding $this of internal instance method + to null). (Nikita) - Mcrypt: . Fixed bug #70625 (mcrypt_encrypt() won't return data when no IV was diff --git a/Zend/tests/bug70681.phpt b/Zend/tests/bug70681.phpt new file mode 100644 index 00000000000..a99180b0ce5 --- /dev/null +++ b/Zend/tests/bug70681.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug #70681: Segfault when binding $this of internal instance method to null +--FILE-- +getClosure(new SplStack); +$c = $c->bindTo(null); + +?> +--EXPECTF-- +Warning: Cannot unbind $this of internal method in %s on line %d diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c index 4430e7b2506..6631193e135 100644 --- a/Zend/zend_closures.c +++ b/Zend/zend_closures.c @@ -173,6 +173,12 @@ ZEND_METHOD(Closure, bind) zend_error(E_WARNING, "Cannot bind an instance to a static closure"); } + if (newthis == NULL && !(closure->func.common.fn_flags & ZEND_ACC_STATIC) + && closure->func.type == ZEND_INTERNAL_FUNCTION) { + zend_error(E_WARNING, "Cannot unbind $this of internal method"); + return; + } + if (scope_arg != NULL) { /* scope argument was given */ if (Z_TYPE_P(scope_arg) == IS_OBJECT) { ce = Z_OBJCE_P(scope_arg);