Skip to content

Commit e69d4f6

Browse files
committed
Avoid in-place modification of referenced data
1 parent 58f7c17 commit e69d4f6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

ext/opcache/Optimizer/zend_optimizer.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ int zend_optimizer_update_op2_const(zend_op_array *op_array,
332332
zend_op *opline,
333333
zval *val)
334334
{
335+
zval tmp;
336+
335337
switch (opline->opcode) {
336338
case ZEND_ASSIGN_REF:
337339
case ZEND_FAST_CALL:
@@ -358,7 +360,13 @@ int zend_optimizer_update_op2_const(zend_op_array *op_array,
358360
break;
359361
case ZEND_INIT_FCALL:
360362
REQUIRES_STRING(val);
361-
zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val));
363+
if (Z_REFCOUNT_P(val) == 1) {
364+
zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val));
365+
} else {
366+
ZVAL_STR(&tmp, zend_string_tolower(Z_STR_P(val)));
367+
zval_ptr_dtor_nogc(val);
368+
val = &tmp;
369+
}
362370
opline->op2.constant = zend_optimizer_add_literal(op_array, val);
363371
alloc_cache_slots_op2(op_array, opline, 1);
364372
break;

0 commit comments

Comments
 (0)