Skip to content

Commit d29e938

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix yet another indirect string modification by error handler problem
2 parents da0d4bf + ddcfffa commit d29e938

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Zend/tests/str_offset_008.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
string offset 008 indirect string modification by error handler
3+
--FILE--
4+
<?php
5+
set_error_handler(function($code, $msg) {
6+
echo "Err: $msg\n";
7+
$GLOBALS['a']=8;
8+
});
9+
$z = "z";
10+
$a=["xx$z"];
11+
var_dump($a[0][$b]);
12+
var_dump($a);
13+
?>
14+
--EXPECT--
15+
Err: Undefined variable $b
16+
Err: String offset cast occurred
17+
string(1) "x"
18+
int(8)

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,15 @@ static zend_string* ZEND_FASTCALL zend_jit_fetch_dim_str_r_helper(zend_string *s
833833
zend_long offset;
834834

835835
if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
836+
if (!(GC_FLAGS(str) & IS_STR_INTERNED)) {
837+
GC_ADDREF(str);
838+
}
836839
offset = zend_check_string_offset(dim/*, BP_VAR_R*/);
840+
if (!(GC_FLAGS(str) & IS_STR_INTERNED) && UNEXPECTED(GC_DELREF(str) == 0)) {
841+
zend_string *ret = zend_jit_fetch_dim_str_offset(str, offset);
842+
zend_string_efree(str);
843+
return ret;
844+
}
837845
} else {
838846
offset = Z_LVAL_P(dim);
839847
}

0 commit comments

Comments
 (0)