Skip to content

Commit ec54ffa

Browse files
committed
Handle throwing destructor in BIND_STATIC
Fixes oss-fuzz #39406.
1 parent 7710047 commit ec54ffa

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

Zend/tests/bind_static_exception.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
BIND_STATIC may destroy a variable with a throwing destructor
3+
--FILE--
4+
<?php
5+
class Test {
6+
function __destruct() {
7+
throw new Exception("Foo");
8+
}
9+
}
10+
try {
11+
$new = new Test;
12+
static $new;
13+
} catch (Exception $e) {
14+
echo $e->getMessage(), "\n";
15+
}
16+
?>
17+
--EXPECT--
18+
Foo

Zend/zend_vm_def.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8652,9 +8652,9 @@ ZEND_VM_HANDLER(183, ZEND_BIND_STATIC, CV, UNUSED, REF)
86528652

86538653
value = (zval*)((char*)ht->arData + (opline->extended_value & ~(ZEND_BIND_REF|ZEND_BIND_IMPLICIT)));
86548654

8655+
SAVE_OPLINE();
86558656
if (opline->extended_value & ZEND_BIND_REF) {
86568657
if (Z_TYPE_P(value) == IS_CONSTANT_AST) {
8657-
SAVE_OPLINE();
86588658
if (UNEXPECTED(zval_update_constant_ex(value, EX(func)->op_array.scope) != SUCCESS)) {
86598659
HANDLE_EXCEPTION();
86608660
}
@@ -8679,7 +8679,7 @@ ZEND_VM_HANDLER(183, ZEND_BIND_STATIC, CV, UNUSED, REF)
86798679
ZVAL_COPY(variable_ptr, value);
86808680
}
86818681

8682-
ZEND_VM_NEXT_OPCODE();
8682+
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
86838683
}
86848684

86858685
ZEND_VM_HOT_HANDLER(184, ZEND_FETCH_THIS, UNUSED, UNUSED)

Zend/zend_vm_execute.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46983,9 +46983,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_BIND_STATIC_SPEC_CV_UNUSED_HAN
4698346983

4698446984
value = (zval*)((char*)ht->arData + (opline->extended_value & ~(ZEND_BIND_REF|ZEND_BIND_IMPLICIT)));
4698546985

46986+
SAVE_OPLINE();
4698646987
if (opline->extended_value & ZEND_BIND_REF) {
4698746988
if (Z_TYPE_P(value) == IS_CONSTANT_AST) {
46988-
SAVE_OPLINE();
4698946989
if (UNEXPECTED(zval_update_constant_ex(value, EX(func)->op_array.scope) != SUCCESS)) {
4699046990
HANDLE_EXCEPTION();
4699146991
}
@@ -47010,7 +47010,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_BIND_STATIC_SPEC_CV_UNUSED_HAN
4701047010
ZVAL_COPY(variable_ptr, value);
4701147011
}
4701247012

47013-
ZEND_VM_NEXT_OPCODE();
47013+
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
4701447014
}
4701547015

4701647016
static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CHECK_VAR_SPEC_CV_UNUSED_HANDLER(ZEND_OPCODE_HANDLER_ARGS)

0 commit comments

Comments
 (0)