moriyoshi               Thu Dec 18 04:50:21 2003 EDT

  Added files:                 
    /php-src/ext/mbstring/tests bug26639.phpt 

  Modified files:              
    /php-src/ext/mbstring       mbstring.c 
  Log:
  Fix bug #26639 (mb_convert_variables() clutters variables beyond the references)
  
  
Index: php-src/ext/mbstring/mbstring.c
diff -u php-src/ext/mbstring/mbstring.c:1.205 php-src/ext/mbstring/mbstring.c:1.206
--- php-src/ext/mbstring/mbstring.c:1.205       Wed Dec 10 12:38:45 2003
+++ php-src/ext/mbstring/mbstring.c     Thu Dec 18 04:50:19 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: mbstring.c,v 1.205 2003/12/10 17:38:45 moriyoshi Exp $ */
+/* $Id: mbstring.c,v 1.206 2003/12/18 09:50:19 moriyoshi Exp $ */
 
 /*
  * PHP4 Multibyte String module "mbstring"
@@ -2605,9 +2605,13 @@
                                                        string.len = 
Z_STRLEN_PP(hash_entry);
                                                        ret = 
mbfl_buffer_converter_feed_result(convd, &string, &result);
                                                        if (ret != NULL) {
-                                                               
STR_FREE(Z_STRVAL_PP(hash_entry));
-                                                               
Z_STRVAL_PP(hash_entry) = (char *)ret->val;
-                                                               
Z_STRLEN_PP(hash_entry) = ret->len;
+                                                               if 
((*hash_entry)->refcount > 1) {
+                                                                       
ZVAL_DELREF(*hash_entry);
+                                                                       
MAKE_STD_ZVAL(*hash_entry);
+                                                               } else {
+                                                                       
zval_dtor(*hash_entry);
+                                                               }
+                                                               
ZVAL_STRINGL(*hash_entry, ret->val, ret->len, 0);
                                                        }
                                                }
                                        }
@@ -2617,9 +2621,8 @@
                                string.len = Z_STRLEN_PP(var);
                                ret = mbfl_buffer_converter_feed_result(convd, 
&string, &result);
                                if (ret != NULL) {
-                                       STR_FREE(Z_STRVAL_PP(var));
-                                       Z_STRVAL_PP(var) = (char *)ret->val;
-                                       Z_STRLEN_PP(var) = ret->len;
+                                       zval_dtor(*var);
+                                       ZVAL_STRINGL(*var, ret->val, ret->len, 0);
                                }
                        }
                }

Index: php-src/ext/mbstring/tests/bug26639.phpt
+++ php-src/ext/mbstring/tests/bug26639.phpt
--TEST--
Bug #26639 (mb_convert_variables() clutters variables beyond the references)
--SKIPIF--
<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
--FILE--
<?php
$a = "あいうえお";
$b = $a;
mb_convert_variables("EUC-JP", "Shift_JIS", $b);
debug_zval_dump($a);
debug_zval_dump($b);
unset($a);
unset($b);

$a = "あいうえお";
$b = &$a;
mb_convert_variables("EUC-JP", "Shift_JIS", $b);
debug_zval_dump($a);
debug_zval_dump($b);
unset($a);
unset($b);

$a = "あいうえお";
$b = array($a);
$c = $b;
mb_convert_variables("EUC-JP", "Shift_JIS", $c);
debug_zval_dump($b);
debug_zval_dump($c);
unset($a);
unset($b);
unset($c);

$a = "あいうえお";
$b = array(&$a);
$c = $b;
mb_convert_variables("euc-jp", "shift_jis", $c);
debug_zval_dump($b);
debug_zval_dump($c);
unset($a);
unset($b);
unset($c);

$a = "あいうえお";
$b = array($a);
$c = &$b;
mb_convert_variables("euc-jp", "shift_jis", $c);
debug_zval_dump($b);
debug_zval_dump($c);
unset($a);
unset($b);
unset($c);

$a = "あいうえお";
$b = array(&$a);
$c = &$b;
mb_convert_variables("euc-jp", "shift_jis", $c);
debug_zval_dump($b);
debug_zval_dump($c);
unset($a);
unset($b);
unset($c);
?>
--EXPECT--
string(10) "あいうえお" refcount(2)
string(10) "、「、、、ヲ、ィ、ェ" refcount(2)
string(10) "、「、、、ヲ、ィ、ェ" refcount(1)
string(10) "、「、、、ヲ、ィ、ェ" refcount(1)
array(1) refcount(2){
  [0]=>
  string(10) "あいうえお" refcount(2)
}
array(1) refcount(2){
  [0]=>
  string(10) "、「、、、ヲ、ィ、ェ" refcount(1)
}
array(1) refcount(2){
  [0]=>
  &string(10) "あいうえお" refcount(2)
}
array(1) refcount(2){
  [0]=>
  string(10) "、「、、、ヲ、ィ、ェ" refcount(1)
}
array(1) refcount(1){
  [0]=>
  string(10) "、「、、、ヲ、ィ、ェ" refcount(2)
}
array(1) refcount(1){
  [0]=>
  string(10) "、「、、、ヲ、ィ、ェ" refcount(2)
}
array(1) refcount(1){
  [0]=>
  string(10) "、「、、、ヲ、ィ、ェ" refcount(2)
}
array(1) refcount(1){
  [0]=>
  string(10) "、「、、、ヲ、ィ、ェ" refcount(2)
}

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

Reply via email to