Skip to content

Commit 6f38acf

Browse files
committed
Safely reassign array in usort()
Make sure to destroy the old value only after assigning the new one. Otherwise we may try to double free, e.g. if GC runs during this dtor. This caused an assertion failure in phpro/grumphp and is likely the cause for bug #81603 as well.
1 parent fc35a6b commit 6f38acf

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ext/standard/array.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,8 +988,10 @@ static void php_usort(INTERNAL_FUNCTION_PARAMETERS, bucket_compare_func_t compar
988988

989989
zend_hash_sort(arr, compare_func, renumber);
990990

991-
zval_ptr_dtor(array);
991+
zval garbage;
992+
ZVAL_COPY_VALUE(&garbage, array);
992993
ZVAL_ARR(array, arr);
994+
zval_ptr_dtor(&garbage);
993995

994996
PHP_ARRAY_CMP_FUNC_RESTORE();
995997
RETURN_TRUE;

0 commit comments

Comments
 (0)