1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fixed bug #78868 (Calling __autoload() with incorrect EG(fake_scope) value)

This commit is contained in:
Dmitry Stogov
2019-11-25 14:05:43 +03:00
parent e1da72bdf1
commit bb30fe9e2b
3 changed files with 41 additions and 0 deletions

2
NEWS
View File

@@ -5,6 +5,8 @@ PHP NEWS
- Core:
. Fixed bug #78787 (Segfault with trait overriding inherited private shadow
property). (Nikita)
. Fixed bug #78868 (Calling __autoload() with incorrect EG(fake_scope) value).
(Antony Dovgal, Dmitry)
- GD:
. Fixed bug #78849 (GD build broken with -D SIGNED_COMPARE_SLOW). (cmb)

33
Zend/tests/bug78868.phpt Normal file
View File

@@ -0,0 +1,33 @@
--TEST--
Bug #78868: Calling __autoload() with incorrect EG(fake_scope) value
--FILE--
<?php
class C {
private $private = 1;
function foo() {
$this->private++; //fails with EG(fake_scope) != NULL && EG(fake_scope) != "C"
}
}
class A {
static $foo = B::foo; //not resolved on include()
}
function main_autoload($class_name) {
$c = new C;
$c->foo();
//doesn't affect the error
eval("class B {const foo = 1;}");
}
spl_autoload_register('main_autoload', false);
$classA = new ReflectionClass("A");
$props = $classA->getProperties();
$props[0]->setValue(2); //causes constant resolving, which runs autoload, all with EG(fake_scope) == "A"
echo "OK\n";
?>
--EXPECT--
OK

View File

@@ -4082,6 +4082,12 @@ ZEND_API int zend_update_static_property_ex(zend_class_entry *scope, zend_string
zval *property;
zend_class_entry *old_scope = EG(fake_scope);
if (UNEXPECTED(!(scope->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) {
if (UNEXPECTED(zend_update_class_constants(scope)) != SUCCESS) {
return FAILURE;
}
}
EG(fake_scope) = scope;
property = zend_std_get_static_property(scope, name, 0);
EG(fake_scope) = old_scope;