Skip to content

Commit bcd7352

Browse files
committed
Fix uninitialized reads in min/max
We need to use the unstable comparison function here, the fallback order is not initialized in this context.
1 parent afafe54 commit bcd7352

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

ext/standard/array.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,13 +1297,12 @@ PHP_FUNCTION(min)
12971297

12981298
/* mixed min ( array $values ) */
12991299
if (argc == 1) {
1300-
zval *result;
1301-
13021300
if (Z_TYPE(args[0]) != IS_ARRAY) {
13031301
zend_argument_type_error(1, "must be of type array, %s given", zend_zval_type_name(&args[0]));
13041302
RETURN_THROWS();
13051303
} else {
1306-
if ((result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare, 0)) != NULL) {
1304+
zval *result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare_unstable, 0);
1305+
if (result) {
13071306
ZVAL_COPY_DEREF(return_value, result);
13081307
} else {
13091308
zend_argument_value_error(1, "must contain at least one element");
@@ -1344,13 +1343,12 @@ PHP_FUNCTION(max)
13441343

13451344
/* mixed max ( array $values ) */
13461345
if (argc == 1) {
1347-
zval *result;
1348-
13491346
if (Z_TYPE(args[0]) != IS_ARRAY) {
13501347
zend_argument_type_error(1, "must be of type array, %s given", zend_zval_type_name(&args[0]));
13511348
RETURN_THROWS();
13521349
} else {
1353-
if ((result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare, 1)) != NULL) {
1350+
zval *result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare_unstable, 1);
1351+
if (result) {
13541352
ZVAL_COPY_DEREF(return_value, result);
13551353
} else {
13561354
zend_argument_value_error(1, "must contain at least one element");

0 commit comments

Comments
 (0)