Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ PHP NEWS
. Fixed function JIT ASSIGN_DIM reporting an undefined value or key out of
order, or when the VM does not, on non-array containers. (Jorg Sowa)
. Fix JIT register allocation for ASSIGN to traced reference. (ndossche)
. Fixed a double free when a destructor throws while freeing a temporary
whose result the optimizer discarded. (Ilia Alshanetsky)

- PDO_Firebird:
. Fixed stack buffer overflow with long connection user names, passwords,
Expand Down
1 change: 1 addition & 0 deletions Zend/Optimizer/dce.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ static bool dce_instr(context *ctx, zend_op *opline, zend_ssa_op *ssa_op) {
opline->opcode = ZEND_FREE;
opline->op1.var = EX_NUM_TO_VAR(ssa->vars[free_var].var);
opline->op1_type = free_var_type;
opline->extended_value = 0;

ssa_op->op1_use = free_var;
ssa_op->op1_use_chain = ssa->vars[free_var].use_chain;
Expand Down
51 changes: 51 additions & 0 deletions ext/opcache/tests/opt/dce_029.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--TEST--
DCE must not keep the replaced instruction's extended_value on a synthesized FREE
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
opcache.file_update_protection=0
opcache.jit=disable
--EXTENSIONS--
opcache
--FILE--
<?php
class D {
public function __destruct() {
throw new Exception("dtor");
}
}

final class C {
public array $a;

public function __construct() {
$this->a = [new D];
}

public function clobber(): int {
$this->a = [];
return 0;
}

public function test() {
empty(($this->a ?? [])[$this->clobber()]);
}
}

$c = new C;
try {
$c->test();
} catch (Exception $e) {
echo $e::class, ": ", $e->getMessage(), "\n";
}

$a = [];
for ($i = 0; $i < 10; $i++) {
$a[] = [$i];
}
echo count($a), "\n";
?>
--EXPECT--
Exception: dtor
10
Loading