cvs: php-src /ext/mbstring mbstring.c /ext/mbstring/tests bug26639.phpt
| From: | Moriyoshi Koizumi | Date: | Thu, 18 Dec 2003 09:50:21 +0000 |
| Subject: | cvs: php-src /ext/mbstring mbstring.c /ext/mbstring/tests bug26639.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-25274@lists.php.net to get a copy of this message | ||
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)
}