From 35c40932e86b57e3eb8fac441522e9fa86f11ed8 Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Tue, 1 Jul 2003 19:13:50 +0000 Subject: [PATCH] Fix destructor visibility --- Zend/zend_object_handlers.c | 2 +- Zend/zend_object_handlers.h | 2 ++ Zend/zend_objects.c | 19 +++++++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 0181a0cc4b..20f0450b06 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -516,7 +516,7 @@ inline zend_function *zend_check_private(zend_function *fbc, zend_class_entry *c /* Ensures that we're allowed to call a protected method. */ -inline int zend_check_protected(zend_class_entry *ce, zend_class_entry *scope) +int zend_check_protected(zend_class_entry *ce, zend_class_entry *scope) { zend_class_entry *fbc_scope = ce; diff --git a/Zend/zend_object_handlers.h b/Zend/zend_object_handlers.h index 4bf801719c..7cd01bf401 100644 --- a/Zend/zend_object_handlers.h +++ b/Zend/zend_object_handlers.h @@ -104,6 +104,8 @@ zend_bool zend_std_unset_static_property(zend_class_entry *ce, char *property_na #define IS_ZEND_STD_OBJECT(z) ((z).type == IS_OBJECT && (Z_OBJ_HT((z))->get_class_entry != NULL)) #define HAS_CLASS_ENTRY(z) (Z_OBJ_HT(z)->get_class_entry != NULL) +int zend_check_protected(zend_class_entry *ce, zend_class_entry *scope); + #endif /* diff --git a/Zend/zend_objects.c b/Zend/zend_objects.c index 911fc700e5..e998263626 100644 --- a/Zend/zend_objects.c +++ b/Zend/zend_objects.c @@ -26,7 +26,9 @@ static inline void zend_objects_call_destructor(zend_object *object, zend_object_handle handle TSRMLS_DC) { - if (object->ce->destructor) { + zend_function *destructor = object->ce->destructor; + + if (destructor) { zval *obj; zval *destructor_func_name; zval *retval_ptr; @@ -38,13 +40,26 @@ static inline void zend_objects_call_destructor(zend_object *object, zend_object obj->value.obj.handlers = &std_object_handlers; zval_copy_ctor(obj); - /* FIXME: Optimize this so that we use the old_object->ce->destructor function pointer instead of the name */ MAKE_STD_ZVAL(destructor_func_name); destructor_func_name->type = IS_STRING; destructor_func_name->value.str.val = estrndup("__destruct", sizeof("__destruct")-1); destructor_func_name->value.str.len = sizeof("__destruct")-1; + if (destructor->op_array.fn_flags & ZEND_ACC_PRIVATE) { + /* Ensure that if we're calling a private function, we're allowed to do so. + */ + if (object->ce != EG(scope)) { + zend_error(E_ERROR, "Call to private destructor from context '%s'", EG(scope) ? EG(scope)->name : ""); + } + } else if ((destructor->common.fn_flags & ZEND_ACC_PROTECTED)) { + /* Ensure that if we're calling a protected function, we're allowed to do so. + */ + if (!zend_check_protected(destructor->common.scope, EG(scope))) { + zend_error(E_ERROR, "Call to protected destructor from context '%s'", EG(scope) ? EG(scope)->name : ""); + } + } + ZEND_INIT_SYMTABLE(&symbol_table); call_user_function_ex(NULL, &obj, destructor_func_name, &retval_ptr, 0, NULL, 0, &symbol_table TSRMLS_CC); -- 2.50.1