Skip to content

Commit 8e14632

Browse files
committed
Merge branch 'PHP-7.0'
2 parents 5ac8a2c + e489883 commit 8e14632

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

ext/intl/collator/collator_sort.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ static void collator_sortkey_swap(collator_sort_key_index_t *p, collator_sort_ke
363363
PHP_FUNCTION( collator_sort_with_sort_keys )
364364
{
365365
zval* array = NULL;
366+
zval garbage;
366367
HashTable* hash = NULL;
367368
zval* hashData = NULL; /* currently processed item of input hash */
368369

@@ -505,7 +506,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
505506
zend_sort( sortKeyIndxBuf, sortKeyCount,
506507
sortKeyIndxSize, collator_cmp_sort_keys, (swap_func_t)collator_sortkey_swap);
507508

508-
zval_ptr_dtor( array );
509+
ZVAL_COPY_VALUE(&garbage, array);
509510
/* for resulting hash we'll assign new hash keys rather then reordering */
510511
array_init(array);
511512

@@ -518,6 +519,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
518519
if( utf16_buf )
519520
efree( utf16_buf );
520521

522+
zval_ptr_dtor(&garbage);
521523
efree( sortKeyIndxBuf );
522524
efree( sortKeyBuf );
523525

ext/intl/tests/bug71020.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #71020 (Use after free in Collator::sortWithSortKeys)
3+
--SKIPIF--
4+
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
5+
--FILE--
6+
<?php
7+
8+
$var_3=new Collator("Whatever");
9+
for($x=0;$x<0xbb;$x++)
10+
$myarray[substr(md5(microtime()),rand(0,26),9) . strval($x)]= substr(md5(microtime()),rand(0,26),9) . strval($x);
11+
$var_3->sortWithSortKeys($myarray);
12+
?>
13+
okey
14+
--EXPECT--
15+
okey

0 commit comments

Comments
 (0)