Permalink
Browse files

Fixed bug #64007 (There is an ability to create instance of Generator…

… by hand).

Use get_constrctor instead of access of the ce->constructor directly
  • Loading branch information...
laruence committed Jan 19, 2013
1 parent e23fca8 commit f7b99c481d0a943d922e99ad9afa82c45193030e
Showing with 29 additions and 8 deletions.
  1. +4 −0 NEWS
  2. +15 −8 ext/reflection/php_reflection.c
  3. +10 −0 ext/reflection/tests/bug64007.phpt
View
4 NEWS
@@ -42,6 +42,10 @@ PHP NEWS
. Bug #62489: dba_insert not working as expected.
(marc-bennewitz at arcor dot de, Lars)
+- Reflection:
+ . Fixed bug #64007 (There is an ability to create instance of Generator by hand).
+ (Laruence)
+
18 Dec 2012, PHP 5.5.0 Alpha 2
- General improvements:
@@ -4192,32 +4192,40 @@ ZEND_METHOD(reflection_class, newInstance)
{
zval *retval_ptr = NULL;
reflection_object *intern;
- zend_class_entry *ce;
+ zend_class_entry *ce, *old_scope;
+ zend_function *constructor;
METHOD_NOTSTATIC(reflection_class_ptr);
GET_REFLECTION_OBJECT_PTR(ce);
+ object_init_ex(return_value, ce);
+
+ old_scope = EG(scope);
+ EG(scope) = ce;
+ constructor = Z_OBJ_HT_P(return_value)->get_constructor(return_value TSRMLS_CC);
+ EG(scope) = old_scope;
+
/* Run the constructor if there is one */
- if (ce->constructor) {
+ if (constructor) {
zval ***params = NULL;
int num_args = 0;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
if (!(ce->constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Access to non-public constructor of class %s", ce->name);
- return;
+ zval_dtor(return_value);
+ RETURN_NULL();
}
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "*", &params, &num_args) == FAILURE) {
if (params) {
efree(params);
}
+ zval_dtor(return_value);
RETURN_FALSE;
}
- object_init_ex(return_value, ce);
-
fci.size = sizeof(fci);
fci.function_table = EG(function_table);
fci.function_name = NULL;
@@ -4242,6 +4250,7 @@ ZEND_METHOD(reflection_class, newInstance)
zval_ptr_dtor(&retval_ptr);
}
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invocation of %s's constructor failed", ce->name);
+ zval_dtor(return_value);
RETURN_NULL();
}
if (retval_ptr) {
@@ -4250,9 +4259,7 @@ ZEND_METHOD(reflection_class, newInstance)
if (params) {
efree(params);
}
- } else if (!ZEND_NUM_ARGS()) {
- object_init_ex(return_value, ce);
- } else {
+ } else if (ZEND_NUM_ARGS()) {
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name);
}
}
@@ -0,0 +1,10 @@
+--TEST--
+Bug #64007 (There is an ability to create instance of Generator by hand)
+--FILE--
+<?php
+$reflection = new ReflectionClass('Generator');
+$generator = $reflection->newInstance();
+var_dump($generator);
+?>
+--EXPECTF--
+Catchable fatal error: The "Generator" class is reserved for internal use and cannot be manually instantiated in %sbug64007.php on line %d

0 comments on commit f7b99c4

Please sign in to comment.