Skip to content

Commit 903a38e

Browse files
committed
ext/standard: validate sort flags when selecting unstable compare function
1 parent d290960 commit 903a38e

1 file changed

Lines changed: 2 additions & 34 deletions

File tree

ext/standard/array.c

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4916,12 +4916,6 @@ PHP_FUNCTION(array_unique)
49164916

49174917
cmp = php_get_data_compare_func_unstable(sort_type, false);
49184918

4919-
if(cmp == NULL){
4920-
zend_argument_value_error(
4921-
2, "must be one of SORT_REGULAR, SORT_NUMERIC, SORT_STRING, or SORT_LOCALE_STRING");
4922-
RETURN_THROWS();
4923-
}
4924-
49254919
bool in_place = zend_may_modify_arg_in_place(array);
49264920
if (in_place) {
49274921
RETVAL_ARR(Z_ARRVAL_P(array));
@@ -5996,20 +5990,7 @@ PHP_FUNCTION(array_multisort)
59965990
/* We see the next array, so we update the sort flags of
59975991
* the previous array and reset the sort flags. */
59985992
if (i > 0) {
5999-
bucket_compare_func_t cmp =
6000-
php_get_data_compare_func_unstable(
6001-
sort_type, sort_order != PHP_SORT_ASC
6002-
);
6003-
6004-
if (cmp == NULL) {
6005-
zend_argument_value_error(
6006-
2,
6007-
"must be one of SORT_REGULAR, SORT_NUMERIC, SORT_STRING, or SORT_LOCALE_STRING"
6008-
);
6009-
RETURN_THROWS();
6010-
}
6011-
6012-
func[num_arrays - 1] = cmp;
5993+
func[num_arrays - 1] = php_get_data_compare_func_unstable(sort_type, sort_order != PHP_SORT_ASC);
60135994
sort_order = PHP_SORT_ASC;
60145995
sort_type = PHP_SORT_REGULAR;
60155996
}
@@ -6079,20 +6060,7 @@ PHP_FUNCTION(array_multisort)
60796060
}
60806061

60816062
/* Take care of the last array sort flags. */
6082-
bucket_compare_func_t cmp =
6083-
php_get_data_compare_func_unstable(
6084-
sort_type, sort_order != PHP_SORT_ASC
6085-
);
6086-
6087-
if (cmp == NULL) {
6088-
zend_argument_value_error(
6089-
2,
6090-
"must be one of SORT_REGULAR, SORT_NUMERIC, SORT_STRING, or SORT_LOCALE_STRING"
6091-
);
6092-
RETURN_THROWS();
6093-
}
6094-
6095-
func[num_arrays - 1] = cmp;
6063+
func[num_arrays - 1] = php_get_data_compare_func_unstable(sort_type, sort_order != PHP_SORT_ASC);
60966064
bucket_compare_func_t *old_multisort_func = ARRAYG(multisort_func);
60976065
ARRAYG(multisort_func) = func;
60986066

0 commit comments

Comments
 (0)