Zend: Fix memory leak in ++/-- when overloading fetch access

Closes GH-11859
This commit is contained in:
George Peter Banyard 2023-08-02 16:13:09 +01:00
parent 35862641ba
commit fc3df283fb
No known key found for this signature in database
GPG key ID: 3306078E3194AEBD
3 changed files with 36 additions and 42 deletions

View file

@ -0,0 +1,36 @@
--TEST--
Overloaded array access with pre increment/decrement
--FILE--
<?php
set_error_handler(function($severity, $m) {
if (str_starts_with($m, 'Indirect modification of overloaded element')) { return; }
throw new Exception($m, $severity);
});
class Foo implements ArrayAccess {
function offsetGet($index): mixed {
return range(1, 5);
}
function offsetSet($index, $newval): void {
}
function offsetExists($index): bool {
return true;
}
function offsetUnset($index): void {
}
}
$foo = new Foo;
try {
$foo[0]++;
} catch (Throwable $ex) {
echo $ex->getMessage() . "\n";
}
$foo = new Foo;
try {
$foo[0]--;
} catch (Throwable $ex) {
echo $ex->getMessage() . "\n";
}
?>
--EXPECT--
Cannot increment array
Cannot decrement array

View file

@ -1500,13 +1500,6 @@ ZEND_VM_HELPER(zend_pre_inc_helper, VAR|CV, ANY)
}
}
increment_function(var_ptr);
if (UNEXPECTED(EG(exception))) {
/* Smart branch expects result to be set with exceptions */
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_NULL(EX_VAR(opline->result.var));
}
HANDLE_EXCEPTION();
}
} while (0);
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
@ -1559,13 +1552,6 @@ ZEND_VM_HELPER(zend_pre_dec_helper, VAR|CV, ANY)
}
}
decrement_function(var_ptr);
if (UNEXPECTED(EG(exception))) {
/* Smart branch expects result to be set with exceptions */
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_NULL(EX_VAR(opline->result.var));
}
HANDLE_EXCEPTION();
}
} while (0);
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {

28
Zend/zend_vm_execute.h generated
View file

@ -21624,13 +21624,6 @@ static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_pre_inc_help
}
}
increment_function(var_ptr);
if (UNEXPECTED(EG(exception))) {
/* Smart branch expects result to be set with exceptions */
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_NULL(EX_VAR(opline->result.var));
}
HANDLE_EXCEPTION();
}
} while (0);
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
@ -21701,13 +21694,6 @@ static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_pre_dec_help
}
}
decrement_function(var_ptr);
if (UNEXPECTED(EG(exception))) {
/* Smart branch expects result to be set with exceptions */
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_NULL(EX_VAR(opline->result.var));
}
HANDLE_EXCEPTION();
}
} while (0);
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
@ -39007,13 +38993,6 @@ static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_pre_inc_help
}
}
increment_function(var_ptr);
if (UNEXPECTED(EG(exception))) {
/* Smart branch expects result to be set with exceptions */
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_NULL(EX_VAR(opline->result.var));
}
HANDLE_EXCEPTION();
}
} while (0);
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
@ -39083,13 +39062,6 @@ static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_pre_dec_help
}
}
decrement_function(var_ptr);
if (UNEXPECTED(EG(exception))) {
/* Smart branch expects result to be set with exceptions */
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_NULL(EX_VAR(opline->result.var));
}
HANDLE_EXCEPTION();
}
} while (0);
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {