php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61782 __clone/__destruct do not match other methods when checking access controls
Submitted: 2012-04-20 06:46 UTC Modified: -
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: stas@php.net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.4.1RC2 OS:
Private report: No CVE-ID: None
 [2012-04-20 06:46 UTC] stas@php.net
Description:
------------
__clone and __destruct check access to protected methods differently from other 
methods. They have 
custom implementation and while other methods allow access to siblings in the 
same tree to protected 
functions, those do not. See implementation for regular ones:


if (UNEXPECTED(!zend_check_protected(zend_get_function_root_class(fbc), 
EG(scope)))) {
	if (zobj->ce->__call) {
		fbc = zend_get_user_call_function(zobj->ce, method_name, 
method_len);
	} else {
		zend_error_noreturn(E_ERROR, "Call to %s method %s::%s() from 
context '%s'", 
zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), 
method_name, EG(scope) ? 
EG(scope)->name : "");
	}
}

and for __clone:


if (UNEXPECTED(!zend_check_protected(clone->common.scope, EG(scope)))) {
	zend_error_noreturn(E_ERROR, "Call to protected %s::__clone() from 
context '%s'", ce->name, 
EG(scope) ? EG(scope)->name : "");
}

it can be seen that __clone does not use zend_get_function_root_class(). Same 
happens for destructor.

I see no reason for that and I think they should be brought in sync with the 
rest of the code. See also: 
http://www.mail-archive.com/internals@lists.php.net/msg57424.html

Test script:
---------------
 abstract class BaseClass {
        abstract protected function __clone();
    }

    class MommasBoy extends BaseClass {
        protected function __clone() {
            echo __METHOD__, "\n";
        }
    }

    class LatchkeyKid extends BaseClass {
        public function __construct() {
            echo 'In ', __CLASS__, ":\n";
            $kid = new MommasBoy();
            $kid = clone $kid;
        }
        public function __clone() {}
    }

    $obj = new LatchkeyKid();


Expected result:
----------------
In LatchkeyKid:
MommasBoy::__clone


Actual result:
--------------
Fatal error: Call to protected MommasBoy::__clone() from context 'LatchkeyKid' in 
bug.php on line 16


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-13 21:48 UTC] stas@php.net
Automatic comment on behalf of stas
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a0dff6fdcae1f4eaa96e68d1429fd38876c2796e
Log: fix bug #61782 - __clone/__destruct do not match other methods when checking access controls
 [2012-05-14 18:03 UTC] stas@php.net
Automatic comment on behalf of stas
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d03900dc92af6d47921143f226217eae3ca564b7
Log: fix bug #61782 - __clone/__destruct do not match other methods when checking access controls
 [2012-05-15 07:45 UTC] mike@php.net
Automatic comment on behalf of stas
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a0dff6fdcae1f4eaa96e68d1429fd38876c2796e
Log: fix bug #61782 - __clone/__destruct do not match other methods when checking access controls
 [2012-07-24 23:36 UTC] rasmus@php.net
Automatic comment on behalf of stas
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d03900dc92af6d47921143f226217eae3ca564b7
Log: fix bug #61782 - __clone/__destruct do not match other methods when checking access controls
 [2013-09-27 12:04 UTC] r dot wilczek at web-appz dot de
reproducable in PHP 5.5.2

class Foo {
    public function getClone() {
        return clone $this;
    }

    private function __clone() {}

}

class Bar extends Foo {}

(new Bar)->getClone();

// Call to private Bar::__clone() from context 'Foo'
 [2013-11-17 09:32 UTC] laruence@php.net
Automatic comment on behalf of stas
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d03900dc92af6d47921143f226217eae3ca564b7
Log: fix bug #61782 - __clone/__destruct do not match other methods when checking access controls
 [2013-11-17 09:32 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2014-10-07 23:26 UTC] stas@php.net
Automatic comment on behalf of stas
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=a0dff6fdcae1f4eaa96e68d1429fd38876c2796e
Log: fix bug #61782 - __clone/__destruct do not match other methods when checking access controls
 [2014-10-07 23:36 UTC] stas@php.net
Automatic comment on behalf of stas
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=a0dff6fdcae1f4eaa96e68d1429fd38876c2796e
Log: fix bug #61782 - __clone/__destruct do not match other methods when checking access controls
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC