Skip to content
Merged
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
4 changes: 2 additions & 2 deletions Zend/Optimizer/block_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
} else if (opline->op1_type == IS_TMP_VAR &&
!zend_bitset_in(used_ext, VAR_NUM(opline->op1.var))) {
src = VAR_SOURCE(opline->op1);
if (src) {
if (src && (src->op1_type != IS_VAR)) {
if (src->opcode == ZEND_BOOL_NOT) {
VAR_SOURCE(opline->op1) = NULL;
COPY_NODE(opline->op1, src->op1);
Expand Down Expand Up @@ -692,7 +692,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
(!zend_bitset_in(used_ext, VAR_NUM(opline->op1.var)) ||
opline->result.var == opline->op1.var)) {
src = VAR_SOURCE(opline->op1);
if (src) {
if (src && (src->op1_type != IS_VAR)) {
if (src->opcode == ZEND_BOOL ||
src->opcode == ZEND_QM_ASSIGN) {
VAR_SOURCE(opline->op1) = NULL;
Expand Down
20 changes: 20 additions & 0 deletions ext/opcache/tests/gh21691.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
GH-21691 (OPcache CFG optimizer breaks reference returns with JMPZ/JMPZ_EX)
--INI--
opcache.enable=1
opcache.enable_cli=1
--EXTENSIONS--
opcache
--FILE--
<?php

function &getData() {
return $x;
}

$data = &getData() && isset($data['key']);
var_dump($data);

?>
--EXPECT--
NULL
21 changes: 21 additions & 0 deletions ext/standard/tests/serialize/serialize_array_ref_reentrancy.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
serialize(): a by-reference __serialize() that grows the array being walked must not free it
--FILE--
<?php
class G {
public $ref;
public function __serialize(): array {
for ($i = 0; $i < 128; $i++) {
$this->ref[] = 'x' . $i;
}
return ['d' => 1];
}
}
$g = new G();
$inner = [$g, 'tail'];
$g->ref = &$inner;
$top = [&$inner];
var_dump(serialize($top));
?>
--EXPECT--
string(59) "a:1:{i:0;a:2:{i:0;O:1:"G":1:{s:1:"d";i:1;}i:1;s:4:"tail";}}"
8 changes: 6 additions & 2 deletions ext/standard/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -1303,13 +1303,17 @@ static void php_var_serialize_intern(smart_str *buf, zval *struc, php_serialize_
zend_release_properties(myht);
return;
}
case IS_ARRAY:
case IS_ARRAY: {
smart_str_appendl(buf, "a:", 2);
myht = Z_ARRVAL_P(struc);
bool rcn = !is_root && (in_rcn_array || GC_REFCOUNT(myht) > 1);
GC_TRY_ADDREF(myht);
php_var_serialize_nested_data(
buf, struc, myht, zend_array_count(myht), /* incomplete_class */ false, var_hash,
!is_root && (in_rcn_array || GC_REFCOUNT(myht) > 1));
rcn);
GC_TRY_DTOR_NO_REF(myht);
return;
}
case IS_REFERENCE:
struc = Z_REFVAL_P(struc);
goto again;
Expand Down