Skip to content

Commit 6556846

Browse files
committed
Fixed bug #79818
Only destroy the variable directly before reassigning it. The value could be read in the meantime.
1 parent f328594 commit 6556846

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

Zend/tests/bug79818.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #79818: BIND_STATIC frees old variable value too early
3+
--FILE--
4+
<?php
5+
function test($a) {
6+
static $a = UNDEFINED;
7+
}
8+
test(new stdClass);
9+
?>
10+
--EXPECTF--
11+
Fatal error: Uncaught Error: Undefined constant 'UNDEFINED' in %s:%d
12+
Stack trace:
13+
#0 %s(%d): test(Object(stdClass))
14+
#1 {main}
15+
thrown in %s on line %d

Zend/zend_vm_def.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8231,7 +8231,6 @@ ZEND_VM_HANDLER(183, ZEND_BIND_STATIC, CV, UNUSED, REF)
82318231
zval *variable_ptr;
82328232

82338233
variable_ptr = GET_OP1_ZVAL_PTR_PTR_UNDEF(BP_VAR_W);
8234-
i_zval_ptr_dtor(variable_ptr);
82358234

82368235
ht = ZEND_MAP_PTR_GET(EX(func)->op_array.static_variables_ptr);
82378236
if (!ht) {
@@ -8252,10 +8251,11 @@ ZEND_VM_HANDLER(183, ZEND_BIND_STATIC, CV, UNUSED, REF)
82528251
if (Z_TYPE_P(value) == IS_CONSTANT_AST) {
82538252
SAVE_OPLINE();
82548253
if (UNEXPECTED(zval_update_constant_ex(value, EX(func)->op_array.scope) != SUCCESS)) {
8255-
ZVAL_NULL(variable_ptr);
82568254
HANDLE_EXCEPTION();
82578255
}
82588256
}
8257+
8258+
i_zval_ptr_dtor(variable_ptr);
82598259
if (UNEXPECTED(!Z_ISREF_P(value))) {
82608260
zend_reference *ref = (zend_reference*)emalloc(sizeof(zend_reference));
82618261
GC_SET_REFCOUNT(ref, 2);
@@ -8270,6 +8270,7 @@ ZEND_VM_HANDLER(183, ZEND_BIND_STATIC, CV, UNUSED, REF)
82708270
ZVAL_REF(variable_ptr, Z_REF_P(value));
82718271
}
82728272
} else {
8273+
i_zval_ptr_dtor(variable_ptr);
82738274
ZVAL_COPY(variable_ptr, value);
82748275
}
82758276

Zend/zend_vm_execute.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45225,7 +45225,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_BIND_STATIC_SPEC_CV_UNUSED_HAN
4522545225
zval *variable_ptr;
4522645226

4522745227
variable_ptr = EX_VAR(opline->op1.var);
45228-
i_zval_ptr_dtor(variable_ptr);
4522945228

4523045229
ht = ZEND_MAP_PTR_GET(EX(func)->op_array.static_variables_ptr);
4523145230
if (!ht) {
@@ -45246,10 +45245,11 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_BIND_STATIC_SPEC_CV_UNUSED_HAN
4524645245
if (Z_TYPE_P(value) == IS_CONSTANT_AST) {
4524745246
SAVE_OPLINE();
4524845247
if (UNEXPECTED(zval_update_constant_ex(value, EX(func)->op_array.scope) != SUCCESS)) {
45249-
ZVAL_NULL(variable_ptr);
4525045248
HANDLE_EXCEPTION();
4525145249
}
4525245250
}
45251+
45252+
i_zval_ptr_dtor(variable_ptr);
4525345253
if (UNEXPECTED(!Z_ISREF_P(value))) {
4525445254
zend_reference *ref = (zend_reference*)emalloc(sizeof(zend_reference));
4525545255
GC_SET_REFCOUNT(ref, 2);
@@ -45264,6 +45264,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_BIND_STATIC_SPEC_CV_UNUSED_HAN
4526445264
ZVAL_REF(variable_ptr, Z_REF_P(value));
4526545265
}
4526645266
} else {
45267+
i_zval_ptr_dtor(variable_ptr);
4526745268
ZVAL_COPY(variable_ptr, value);
4526845269
}
4526945270

0 commit comments

Comments
 (0)