Skip to content

Commit

Permalink
- Fix #31651 (ReflectionClass::getDefaultProperties segfaults with ar…
Browse files Browse the repository at this point in the history
…rays.)
  • Loading branch information
helly25 committed Jan 22, 2005
1 parent bad9862 commit 1d5c13b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
16 changes: 11 additions & 5 deletions Zend/zend_API.c
Expand Up @@ -709,6 +709,16 @@ ZEND_API void zend_merge_properties(zval *obj, HashTable *properties, int destro
} }




ZEND_API void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC)
{
if (!class_type->constants_updated) {
zend_hash_apply_with_argument(&class_type->default_properties, (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
zend_hash_apply_with_argument(class_type->static_members, (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
class_type->constants_updated = 1;
}
}


/* This function requires 'properties' to contain all props declared in the /* This function requires 'properties' to contain all props declared in the
* class and all props being public. If only a subset is given or the class * class and all props being public. If only a subset is given or the class
* has protected members then you need to merge the properties seperately by * has protected members then you need to merge the properties seperately by
Expand All @@ -723,11 +733,7 @@ ZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *class_type
zend_error(E_ERROR, "Cannot instantiate %s %s", what, class_type->name); zend_error(E_ERROR, "Cannot instantiate %s %s", what, class_type->name);
} }


if (!class_type->constants_updated) { zend_update_class_constants(class_type TSRMLS_CC);
zend_hash_apply_with_argument(&class_type->default_properties, (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
zend_hash_apply_with_argument(class_type->static_members, (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
class_type->constants_updated = 1;
}


arg->type = IS_OBJECT; arg->type = IS_OBJECT;
if (class_type->create_object == NULL) { if (class_type->create_object == NULL) {
Expand Down
1 change: 1 addition & 0 deletions Zend/zend_API.h
Expand Up @@ -191,6 +191,7 @@ ZEND_API int zend_declare_property_null(zend_class_entry *ce, char *name, int na
ZEND_API int zend_declare_property_long(zend_class_entry *ce, char *name, int name_length, long value, int access_type TSRMLS_DC); ZEND_API int zend_declare_property_long(zend_class_entry *ce, char *name, int name_length, long value, int access_type TSRMLS_DC);
ZEND_API int zend_declare_property_string(zend_class_entry *ce, char *name, int name_length, char *value, int access_type TSRMLS_DC); ZEND_API int zend_declare_property_string(zend_class_entry *ce, char *name, int name_length, char *value, int access_type TSRMLS_DC);


ZEND_API void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC);
ZEND_API void zend_update_property(zend_class_entry *scope, zval *object, char *name, int name_length, zval *value TSRMLS_DC); ZEND_API void zend_update_property(zend_class_entry *scope, zval *object, char *name, int name_length, zval *value TSRMLS_DC);
ZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, char *name, int name_length TSRMLS_DC); ZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, char *name, int name_length TSRMLS_DC);
ZEND_API void zend_update_property_long(zend_class_entry *scope, zval *object, char *name, int name_length, long value TSRMLS_DC); ZEND_API void zend_update_property_long(zend_class_entry *scope, zval *object, char *name, int name_length, long value TSRMLS_DC);
Expand Down
8 changes: 3 additions & 5 deletions Zend/zend_reflection_api.c
Expand Up @@ -2296,11 +2296,7 @@ ZEND_METHOD(reflection_class, getStaticProperties)
METHOD_NOTSTATIC_NUMPARAMS(0); METHOD_NOTSTATIC_NUMPARAMS(0);
GET_REFLECTION_OBJECT_PTR(ce); GET_REFLECTION_OBJECT_PTR(ce);


if (!ce->constants_updated) { zend_update_class_constants(ce TSRMLS_CC);
zend_hash_apply_with_argument(&ce->default_properties, (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
zend_hash_apply_with_argument(ce->static_members, (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
ce->constants_updated = 1;
}


array_init(return_value); array_init(return_value);
zend_hash_copy(Z_ARRVAL_P(return_value), ce->static_members, (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *)); zend_hash_copy(Z_ARRVAL_P(return_value), ce->static_members, (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *));
Expand All @@ -2319,6 +2315,8 @@ ZEND_METHOD(reflection_class, getDefaultProperties)
GET_REFLECTION_OBJECT_PTR(ce); GET_REFLECTION_OBJECT_PTR(ce);
array_init(return_value); array_init(return_value);


zend_update_class_constants(ce TSRMLS_CC);

count = zend_hash_num_elements(&ce->default_properties); count = zend_hash_num_elements(&ce->default_properties);
if (count > 0) { if (count > 0) {
HashPosition pos; HashPosition pos;
Expand Down
8 changes: 3 additions & 5 deletions ext/reflection/php_reflection.c
Expand Up @@ -2296,11 +2296,7 @@ ZEND_METHOD(reflection_class, getStaticProperties)
METHOD_NOTSTATIC_NUMPARAMS(0); METHOD_NOTSTATIC_NUMPARAMS(0);
GET_REFLECTION_OBJECT_PTR(ce); GET_REFLECTION_OBJECT_PTR(ce);


if (!ce->constants_updated) { zend_update_class_constants(ce TSRMLS_CC);
zend_hash_apply_with_argument(&ce->default_properties, (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
zend_hash_apply_with_argument(ce->static_members, (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
ce->constants_updated = 1;
}


array_init(return_value); array_init(return_value);
zend_hash_copy(Z_ARRVAL_P(return_value), ce->static_members, (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *)); zend_hash_copy(Z_ARRVAL_P(return_value), ce->static_members, (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *));
Expand All @@ -2319,6 +2315,8 @@ ZEND_METHOD(reflection_class, getDefaultProperties)
GET_REFLECTION_OBJECT_PTR(ce); GET_REFLECTION_OBJECT_PTR(ce);
array_init(return_value); array_init(return_value);


zend_update_class_constants(ce TSRMLS_CC);

count = zend_hash_num_elements(&ce->default_properties); count = zend_hash_num_elements(&ce->default_properties);
if (count > 0) { if (count > 0) {
HashPosition pos; HashPosition pos;
Expand Down

0 comments on commit 1d5c13b

Please sign in to comment.