Skip to content

Commit 0ee4371

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix exception handling in array_multisort()
2 parents 7c7698f + b2ec6c2 commit 0ee4371

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ PHP NEWS
77

88
- Standard:
99
. Fix access on NULL pointer in array_merge_recursive(). (ilutov)
10+
. Fix exception handling in array_multisort(). (ilutov)
1011

1112
01 Jun 2023, PHP 8.2.7
1213

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Exception handling in array_multisort()
3+
--FILE--
4+
<?php
5+
$array = [1 => new DateTime(), 0 => new DateTime()];
6+
array_multisort($array, SORT_STRING);
7+
?>
8+
--EXPECTF--
9+
Fatal error: Uncaught Error: Object of class DateTime could not be converted to string in %s:%d
10+
Stack trace:
11+
#0 %s(%d): array_multisort(Array, 2)
12+
#1 {main}
13+
thrown in %s on line %d

ext/standard/array.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -5761,6 +5761,9 @@ PHP_FUNCTION(array_multisort)
57615761

57625762
/* Do the actual sort magic - bada-bim, bada-boom. */
57635763
zend_sort(indirect, array_size, sizeof(Bucket *), php_multisort_compare, (swap_func_t)array_bucket_p_sawp);
5764+
if (EG(exception)) {
5765+
goto clean_up;
5766+
}
57645767

57655768
/* Restructure the arrays based on sorted indirect - this is mostly taken from zend_hash_sort() function. */
57665769
for (i = 0; i < num_arrays; i++) {
@@ -5790,15 +5793,15 @@ PHP_FUNCTION(array_multisort)
57905793
}
57915794
}
57925795
}
5796+
RETVAL_TRUE;
57935797

5794-
/* Clean up. */
5798+
clean_up:
57955799
for (i = 0; i < array_size; i++) {
57965800
efree(indirect[i]);
57975801
}
57985802
efree(indirect);
57995803
efree(func);
58005804
efree(arrays);
5801-
RETURN_TRUE;
58025805
}
58035806
/* }}} */
58045807

0 commit comments

Comments
 (0)