com php-src: Fixed bug #70685: NEWS Zend/tests/bug70685.phpt Zend/zend_closures.c

From: Date: Sat, 10 Oct 2015 12:59:21 +0000
Subject: com php-src: Fixed bug #70685: NEWS Zend/tests/bug70685.phpt Zend/zend_closures.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-89353@lists.php.net to get a copy of this message
Commit: d7d01fc9a326fe530df4e067db1df9ec451f4411 Author: Nikita Popov <nikic@php.net> Sat, 10 Oct 2015 14:54:14 +0200 Parents: e19423f3cbeaf2ac57a4af1e7c5b84fc6721177b Branches: PHP-5.6 PHP-7.0 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d7d01fc9a326fe530df4e067db1df9ec451f4411 Log: Fixed bug #70685 Doing a less intrusive variant of the PHP 7.0 fix for 5.6. Bugs: https://bugs.php.net/70685 Changed paths: M NEWS A Zend/tests/bug70685.phpt M Zend/zend_closures.c Diff: diff --git a/NEWS b/NEWS index 90369eb..ca69546 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ PHP NEWS - Core: . Fixed bug #70681 (Segfault when binding $this of internal instance method to null). (Nikita) + . Fixed bug #70685 (Segfault for getClosure() internal method rebind with + invalid $this). (Nikita) - Date: . Fixed bug #70619 (DateTimeImmutable segfault). (Laruence) diff --git a/Zend/tests/bug70685.phpt b/Zend/tests/bug70685.phpt new file mode 100644 index 0000000..e286e58 --- /dev/null +++ b/Zend/tests/bug70685.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #70685: Segfault for getClosure() internal method rebind with invalid $this +--FILE-- +<?php + +class cls {} + +$c = (new ReflectionMethod('SplStack', 'count'))->getClosure(new SplStack); +$c = $c->bindTo(new cls); +var_dump($c); + +$c = (new ReflectionMethod('SplStack', 'count'))->getClosure(new SplStack); +$c = $c->bindTo(new SplStack, 'cls'); +var_dump($c); + +?> +--EXPECTF-- +Warning: Cannot bind internal method SplDoublyLinkedList::count() to object of class cls in %s on line %d +NULL + +Warning: Cannot bind function SplDoublyLinkedList::count to scope class cls in %s on line %d +NULL diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c index 582a1f7..f57d6b5 100644 --- a/Zend/zend_closures.c +++ b/Zend/zend_closures.c @@ -133,6 +133,19 @@ ZEND_METHOD(Closure, bind) ce = closure->func.common.scope; } + /* verify that we aren't binding internal function to a wrong scope */ + if (closure->func.type == ZEND_INTERNAL_FUNCTION && closure->func.common.scope != NULL) { + if (ce && !instanceof_function(ce, closure->func.common.scope TSRMLS_CC)) { + zend_error(E_WARNING, "Cannot bind function %s::%s to scope class %s", closure->func.common.scope->name, closure->func.common.function_name, ce->name); + return; + } + if (ce && newthis && (closure->func.common.fn_flags & ZEND_ACC_STATIC) == 0 && + !instanceof_function(Z_OBJCE_P(newthis), closure->func.common.scope TSRMLS_CC)) { + zend_error(E_WARNING, "Cannot bind internal method %s::%s() to object of class %s", closure->func.common.scope->name, closure->func.common.function_name, Z_OBJCE_P(newthis)->name); + return; + } + } + zend_create_closure(return_value, &closure->func, ce, newthis TSRMLS_CC); } /* }}} */ @@ -470,19 +483,7 @@ ZEND_API void zend_create_closure(zval *res, zend_function *func, zend_class_ent closure->func.op_array.run_time_cache = NULL; (*closure->func.op_array.refcount)++; } else { - /* verify that we aren't binding internal function to a wrong scope */ - if(func->common.scope != NULL) { - if(scope && !instanceof_function(scope, func->common.scope TSRMLS_CC)) { - zend_error(E_WARNING, "Cannot bind function %s::%s to scope class %s", func->common.scope->name, func->common.function_name, scope->name); - scope = NULL; - } - if(scope && this_ptr && (func->common.fn_flags & ZEND_ACC_STATIC) == 0 && - !instanceof_function(Z_OBJCE_P(this_ptr), closure->func.common.scope TSRMLS_CC)) { - zend_error(E_WARNING, "Cannot bind function %s::%s to object of class %s", func->common.scope->name, func->common.function_name, Z_OBJCE_P(this_ptr)->name); - scope = NULL; - this_ptr = NULL; - } - } else { + if (!func->common..scope) { /* if it's a free function, we won't set scope & this since they're meaningless */ this_ptr = NULL; scope = NULL;

« previous php.cvs (#89353) next »