Skip to content

Commit

Permalink
Fix uninitialized reads in min/max
Browse files Browse the repository at this point in the history
We need to use the unstable comparison function here, the fallback
order is not initialized in this context.
  • Loading branch information
nikic committed Jun 26, 2020
1 parent afafe54 commit bcd7352
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1297,13 +1297,12 @@ PHP_FUNCTION(min)

/* mixed min ( array $values ) */
if (argc == 1) {
zval *result;

if (Z_TYPE(args[0]) != IS_ARRAY) {
zend_argument_type_error(1, "must be of type array, %s given", zend_zval_type_name(&args[0]));
RETURN_THROWS();
} else {
if ((result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare, 0)) != NULL) {
zval *result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare_unstable, 0);
if (result) {
ZVAL_COPY_DEREF(return_value, result);
} else {
zend_argument_value_error(1, "must contain at least one element");
Expand Down Expand Up @@ -1344,13 +1343,12 @@ PHP_FUNCTION(max)

/* mixed max ( array $values ) */
if (argc == 1) {
zval *result;

if (Z_TYPE(args[0]) != IS_ARRAY) {
zend_argument_type_error(1, "must be of type array, %s given", zend_zval_type_name(&args[0]));
RETURN_THROWS();
} else {
if ((result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare, 1)) != NULL) {
zval *result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare_unstable, 1);
if (result) {
ZVAL_COPY_DEREF(return_value, result);
} else {
zend_argument_value_error(1, "must contain at least one element");
Expand Down

0 comments on commit bcd7352

Please sign in to comment.