iliaa Sun Oct 28 13:44:09 2007 UTC Modified files: /php-src/ext/reflection/tests bug42976.phpt /php-src/ext/reflection php_reflection.c Log: MFB: Fixed bug #42976 (Crash when constructor for newInstance() or newInstanceArgs() fails) http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/bug42976.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/reflection/tests/bug42976.phpt diff -u /dev/null php-src/ext/reflection/tests/bug42976.phpt:1.2 --- /dev/null Sun Oct 28 13:44:09 2007 +++ php-src/ext/reflection/tests/bug42976.phpt Sun Oct 28 13:44:09 2007 @@ -0,0 +1,34 @@ +--TEST-- +Bug #42976 (Crash when constructor for newInstance() or newInstanceArgs() fails) +--FILE-- +<?php + +Class C { + function __construct(&$x) { + $x = "x.changed"; + } +} + +$x = "x.original"; +new C($x); // OK +var_dump($x); + +$rc = new ReflectionClass('C'); +$x = "x.original"; +$rc->newInstance($x); // causes crash +var_dump($x); +$x = "x.original"; +$rc->newInstanceArgs(array($x)); // causes crash +var_dump($x); + +echo "Done\n"; +?> +--EXPECTF-- +string(9) "x.changed" + +Warning: Invocation of C's constructor failed in %s/bug42976.php on line %d +string(10) "x.original" + +Warning: Invocation of C's constructor failed in %s/bug42976.php on line %d +string(10) "x.original" +Done http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/php_reflection.c?r1=1.286&r2=1.287&diff_format=u Index: php-src/ext/reflection/php_reflection.c diff -u php-src/ext/reflection/php_reflection.c:1.286 php-src/ext/reflection/php_reflection.c:1.287 --- php-src/ext/reflection/php_reflection.c:1.286 Sun Oct 7 05:15:04 2007 +++ php-src/ext/reflection/php_reflection.c Sun Oct 28 13:44:09 2007 @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_reflection.c,v 1.286 2007/10/07 05:15:04 davidw Exp $ */ +/* $Id: php_reflection.c,v 1.287 2007/10/28 13:44:09 iliaa Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -3484,7 +3484,7 @@ Returns an instance of this class */ ZEND_METHOD(reflection_class, newInstance) { - zval *retval_ptr; + zval *retval_ptr = NULL; reflection_object *intern; zend_class_entry *ce; int argc = ZEND_NUM_ARGS(); @@ -3528,7 +3528,9 @@ if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { efree(params); - zval_ptr_dtor(&retval_ptr); + if (retval_ptr) { + zval_ptr_dtor(&retval_ptr); + } zend_error(E_WARNING, "Invocation of %v's constructor failed", ce->name); RETURN_NULL(); } @@ -3548,7 +3550,7 @@ Returns an instance of this class */ ZEND_METHOD(reflection_class, newInstanceArgs) { - zval *retval_ptr; + zval *retval_ptr = NULL; reflection_object *intern; zend_class_entry *ce; int argc = 0; @@ -3603,7 +3605,9 @@ if (params) { efree(params); } - zval_ptr_dtor(&retval_ptr); + if (retval_ptr) { + zval_ptr_dtor(&retval_ptr); + } zend_error(E_WARNING, "Invocation of %v's constructor failed", ce->name); RETURN_NULL(); } @@ -5022,7 +5026,7 @@ php_info_print_table_start(); php_info_print_table_header(2, "Reflection", "enabled"); - php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 1.286 2007/10/07 05:15:04 davidw Exp $"); + php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 1.287 2007/10/28 13:44:09 iliaa Exp $"); php_info_print_table_end(); } /* }}} */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php