1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.4'

* PHP-8.4:
  Fix memory leaks in array_any() / array_all()
This commit is contained in:
Niels Dossche
2025-03-05 19:53:30 +01:00
2 changed files with 19 additions and 11 deletions

View File

@@ -6629,20 +6629,14 @@ static zend_result php_array_find(const HashTable *array, zend_fcall_info fci, z
zend_result result = zend_call_function(&fci, &fci_cache);
ZEND_ASSERT(result == SUCCESS);
<<<<<<< HEAD
=======
if (EXPECTED(!Z_ISUNDEF(retval))) {
int retval_true;
>>>>>>> 2701b97011 (Fix memory leaks in array_any() / array_all())
if (UNEXPECTED(EG(exception))) {
if (UNEXPECTED(Z_ISUNDEF(retval))) {
return FAILURE;
}
bool retval_true = zend_is_true(&retval);
zval_ptr_dtor(&retval);
<<<<<<< HEAD
/* This negates the condition, if negate_condition is true. Otherwise it does nothing with `retval_true`. */
retval_true ^= negate_condition;
@@ -6656,10 +6650,6 @@ static zend_result php_array_find(const HashTable *array, zend_fcall_info fci, z
}
break;
=======
if (UNEXPECTED(Z_ISUNDEF(retval))) {
return FAILURE;
>>>>>>> 2701b97011 (Fix memory leaks in array_any() / array_all())
}
} ZEND_HASH_FOREACH_END();

View File

@@ -0,0 +1,18 @@
--TEST--
array_any() / array_all() leak
--DESCRIPTION--
Found in GH-16831#issuecomment-2700410631
--FILE--
<?php
// Don't touch this str_repeat + random_int combination,
// this is to circumvent SCCP and interning
$key = str_repeat('abc', random_int(3, 3));
var_dump(array_any([$key => 1], static fn () => true));
var_dump(array_all([$key => 1], static fn () => false));
?>
--EXPECT--
bool(true)
bool(false)