tony2001                Mon Jan 22 08:17:26 2007 UTC

  Added files:                 (Branch: PHP_5_2)
    /php-src/ext/standard/tests/array   bug40191.phpt 

  Modified files:              
    /php-src    NEWS 
    /php-src/ext/standard       array.c 
  Log:
  MFH: fix #40191 (use of array_unique() with objects triggers segfault)
  
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.506&r2=1.2027.2.547.2.507&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.506 php-src/NEWS:1.2027.2.547.2.507
--- php-src/NEWS:1.2027.2.547.2.506     Sun Jan 21 19:52:44 2007
+++ php-src/NEWS        Mon Jan 22 08:17:26 2007
@@ -1,6 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? Jan 2007, PHP 5.2.1RC4
+- Fixed bug #40191 (use of array_unique() with objects triggers segfault).
+  (Tony)
 - Fixed bug #40169 (CURLOPT_TCP_NODELAY only available in curl >= 7.11.2). 
   (Tony)
 - Fixed bug #39450 (getenv() fills other super-globals). (Ilia, Tony)
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/array.c?r1=1.308.2.21.2.22&r2=1.308.2.21.2.23&diff_format=u
Index: php-src/ext/standard/array.c
diff -u php-src/ext/standard/array.c:1.308.2.21.2.22 
php-src/ext/standard/array.c:1.308.2.21.2.23
--- php-src/ext/standard/array.c:1.308.2.21.2.22        Mon Jan  1 09:36:07 2007
+++ php-src/ext/standard/array.c        Mon Jan 22 08:17:26 2007
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: array.c,v 1.308.2.21.2.22 2007/01/01 09:36:07 sebastian Exp $ */
+/* $Id: array.c,v 1.308.2.21.2.23 2007/01/22 08:17:26 tony2001 Exp $ */
 
 #include "php.h"
 #include "php_ini.h"
@@ -2792,7 +2792,7 @@
    Removes duplicate values from array */
 PHP_FUNCTION(array_unique)
 {
-       zval **array;
+       zval **array, *tmp;
        HashTable *target_hash;
        Bucket *p;
        struct bucketindex {
@@ -2811,8 +2811,8 @@
                RETURN_FALSE;
        }
 
-       /* copy the argument array */
-       RETVAL_ZVAL(*array, 1, 0);
+       array_init(return_value);
+       zend_hash_copy(Z_ARRVAL_P(return_value), target_hash, 
(copy_ctor_func_t) zval_add_ref, (void *)&tmp, sizeof(zval*));
 
        if (target_hash->nNumOfElements <= 1) { /* nothing to do */
                return;

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/bug40191.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/bug40191.phpt
+++ php-src/ext/standard/tests/array/bug40191.phpt
--TEST--
Bug #40191 (use of array_unique() with objects triggers segfault)
--FILE--
<?php

$arrObj = new ArrayObject();
$arrObj->append('foo');
$arrObj->append('bar');
$arrObj->append('foo');

$arr = array_unique($arrObj);
var_dump($arr);

echo "Done\n";
?>
--EXPECTF--     
array(2) {
  [0]=>
  string(3) "foo"
  [1]=>
  string(3) "bar"
}
Done
--UEXPECTF--
array(2) {
  [0]=>
  unicode(3) "foo"
  [1]=>
  unicode(3) "bar"
}
Done

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to