summaryrefslogtreecommitdiff
path: root/Zend/zend_vm_execute.h
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2014-05-29 00:02:13 +0200
committerNikita Popov <nikic@php.net>2014-05-29 00:15:50 +0200
commitd9a35c7e97da5583c28d2799d64a6fccdf855622 (patch)
tree17050d9fe32b4180a1ffb891aea29f3cf4dd6bec /Zend/zend_vm_execute.h
parentafd8a02160b4773a44f9898557e6eb0ec46f64fc (diff)
downloadphp-git-d9a35c7e97da5583c28d2799d64a6fccdf855622.tar.gz
Fix class constant fetching
If a class is extended after the constant fetch has been cached the cached value will be turned into a reference. On the next fetch the polymorphic cache will return this reference, which will be directly returned. The object assignment code then dereferences this result and performs a shallow copy, which is invalid for references. This subsequently leads to the constant value being prematurely freed. This is fixed by dereferencing the value returned from the polymorphic cache. Furthermore the incorrect dereference from in the object assignment code is replaced with an assertion that we're dealing with a non-reference, so ensure that this kind of problem cannot go unnoticed in the future.
Diffstat (limited to 'Zend/zend_vm_execute.h')
-rw-r--r--Zend/zend_vm_execute.h15
1 files changed, 6 insertions, 9 deletions
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index 2e7184e30d..5b5c69923a 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -3903,15 +3903,14 @@ static int ZEND_FASTCALL ZEND_FETCH_CONSTANT_SPEC_CONST_CONST_HANDLER(ZEND_OPCO
} else {
ce = Z_CE_P(EX_VAR(opline->op1.var));
if ((value = CACHED_POLYMORPHIC_PTR(Z_CACHE_SLOT_P(opline->op2.zv), ce)) != NULL) {
+ ZVAL_DEREF(value);
ZVAL_DUP(EX_VAR(opline->result.var), value);
goto constant_fetch_end;
}
}
if (EXPECTED((value = zend_hash_find(&ce->constants_table, Z_STR_P(opline->op2.zv))) != NULL)) {
- if (Z_ISREF_P(value)) {
- value = Z_REFVAL_P(value);
- }
+ ZVAL_DEREF(value);
if (Z_CONSTANT_P(value)) {
zend_class_entry *old_scope = EG(scope);
@@ -15346,15 +15345,14 @@ static int ZEND_FASTCALL ZEND_FETCH_CONSTANT_SPEC_VAR_CONST_HANDLER(ZEND_OPCODE
} else {
ce = Z_CE_P(EX_VAR(opline->op1.var));
if ((value = CACHED_POLYMORPHIC_PTR(Z_CACHE_SLOT_P(opline->op2.zv), ce)) != NULL) {
+ ZVAL_DEREF(value);
ZVAL_DUP(EX_VAR(opline->result.var), value);
goto constant_fetch_end;
}
}
if (EXPECTED((value = zend_hash_find(&ce->constants_table, Z_STR_P(opline->op2.zv))) != NULL)) {
- if (Z_ISREF_P(value)) {
- value = Z_REFVAL_P(value);
- }
+ ZVAL_DEREF(value);
if (Z_CONSTANT_P(value)) {
zend_class_entry *old_scope = EG(scope);
@@ -24557,15 +24555,14 @@ static int ZEND_FASTCALL ZEND_FETCH_CONSTANT_SPEC_UNUSED_CONST_HANDLER(ZEND_OPC
} else {
ce = Z_CE_P(EX_VAR(opline->op1.var));
if ((value = CACHED_POLYMORPHIC_PTR(Z_CACHE_SLOT_P(opline->op2.zv), ce)) != NULL) {
+ ZVAL_DEREF(value);
ZVAL_DUP(EX_VAR(opline->result.var), value);
goto constant_fetch_end;
}
}
if (EXPECTED((value = zend_hash_find(&ce->constants_table, Z_STR_P(opline->op2.zv))) != NULL)) {
- if (Z_ISREF_P(value)) {
- value = Z_REFVAL_P(value);
- }
+ ZVAL_DEREF(value);
if (Z_CONSTANT_P(value)) {
zend_class_entry *old_scope = EG(scope);