mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Fix exception handling in array_multisort()
Closes GH-11302
This commit is contained in:
parent
f5c54fd88b
commit
b2ec6c24f8
3 changed files with 19 additions and 2 deletions
1
NEWS
1
NEWS
|
@ -4,6 +4,7 @@ PHP NEWS
|
|||
|
||||
- Standard:
|
||||
. Fix access on NULL pointer in array_merge_recursive(). (ilutov)
|
||||
. Fix exception handling in array_multisort(). (ilutov)
|
||||
|
||||
08 Jun 2023, PHP 8.1.20
|
||||
|
||||
|
|
13
Zend/tests/array_multisort_exception.phpt
Normal file
13
Zend/tests/array_multisort_exception.phpt
Normal file
|
@ -0,0 +1,13 @@
|
|||
--TEST--
|
||||
Exception handling in array_multisort()
|
||||
--FILE--
|
||||
<?php
|
||||
$array = [1 => new DateTime(), 0 => new DateTime()];
|
||||
array_multisort($array, SORT_STRING);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Uncaught Error: Object of class DateTime could not be converted to string in %s:%d
|
||||
Stack trace:
|
||||
#0 %s(%d): array_multisort(Array, 2)
|
||||
#1 {main}
|
||||
thrown in %s on line %d
|
|
@ -5598,6 +5598,9 @@ PHP_FUNCTION(array_multisort)
|
|||
|
||||
/* Do the actual sort magic - bada-bim, bada-boom. */
|
||||
zend_sort(indirect, array_size, sizeof(Bucket *), php_multisort_compare, (swap_func_t)array_bucket_p_sawp);
|
||||
if (EG(exception)) {
|
||||
goto clean_up;
|
||||
}
|
||||
|
||||
/* Restructure the arrays based on sorted indirect - this is mostly taken from zend_hash_sort() function. */
|
||||
for (i = 0; i < num_arrays; i++) {
|
||||
|
@ -5623,15 +5626,15 @@ PHP_FUNCTION(array_multisort)
|
|||
zend_hash_rehash(hash);
|
||||
}
|
||||
}
|
||||
RETVAL_TRUE;
|
||||
|
||||
/* Clean up. */
|
||||
clean_up:
|
||||
for (i = 0; i < array_size; i++) {
|
||||
efree(indirect[i]);
|
||||
}
|
||||
efree(indirect);
|
||||
efree(func);
|
||||
efree(arrays);
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue