tony2001 Mon Jan 21 14:37:19 2008 UTC Added files: /php-src/ext/standard/tests/strings bug42861.phpt
Modified files: /php-src/ext/standard string.c Log: fix #42861 (strtr() crashes in Unicode mode when $from argument is empty) http://cvs.php.net/viewvc.cgi/php-src/ext/standard/string.c?r1=1.664&r2=1.665&diff_format=u Index: php-src/ext/standard/string.c diff -u php-src/ext/standard/string.c:1.664 php-src/ext/standard/string.c:1.665 --- php-src/ext/standard/string.c:1.664 Sat Jan 19 19:47:41 2008 +++ php-src/ext/standard/string.c Mon Jan 21 14:37:19 2008 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.664 2008/01/19 19:47:41 davidc Exp $ */ +/* $Id: string.c,v 1.665 2008/01/21 14:37:19 tony2001 Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -4151,6 +4151,7 @@ int can_optimize = 1; if ((trlen < 1) || (len < 1)) { + *outlen = len; return str; } @@ -4270,6 +4271,7 @@ len = string_key_len-1; if (len < 1) { zend_hash_destroy(tmp_hash); + efree(tmp_hash); return NULL; } zend_u_hash_add(tmp_hash, IS_UNICODE, string_key, string_key_len, entry, sizeof(zval*), NULL); @@ -4506,19 +4508,23 @@ } if (Z_TYPE_PP(str) == IS_UNICODE) { - int outlen; + int outlen = 0; UChar *outstr; if (ac == 2) { - int minlen, maxlen; + int minlen = 0, maxlen = 0; HashTable *hash; hash = php_u_strtr_array_prepare_hashtable(HASH_OF(*from), &minlen, &maxlen TSRMLS_CC); - outstr = php_u_strtr_array(Z_USTRVAL_PP(str), Z_USTRLEN_PP(str), hash, minlen, maxlen, &outlen TSRMLS_CC); - zend_hash_destroy(hash); - efree(hash); - RETVAL_UNICODEL(outstr, outlen, 0); - Z_TYPE_P(return_value) = IS_UNICODE; + if (hash) { + outstr = php_u_strtr_array(Z_USTRVAL_PP(str), Z_USTRLEN_PP(str), hash, minlen, maxlen, &outlen TSRMLS_CC); + zend_hash_destroy(hash); + efree(hash); + RETVAL_UNICODEL(outstr, outlen, 0); + Z_TYPE_P(return_value) = IS_UNICODE; + } else { + RETURN_ZVAL(*str, 1, 0); + } } else { convert_to_unicode_ex(from); convert_to_unicode_ex(to); @@ -4531,7 +4537,12 @@ Z_USTRLEN_PP(to), MIN(Z_USTRLEN_PP(from), Z_USTRLEN_PP(to)), &outlen TSRMLS_CC); - ZVAL_UNICODEL(return_value, outstr, outlen, 0); + + if (Z_USTRVAL_PP(str) == outstr) { + ZVAL_UNICODEL(return_value, outstr, outlen, 1); + } else { + ZVAL_UNICODEL(return_value, outstr, outlen, 0); + } Z_TYPE_P(return_value) = IS_UNICODE; } http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/bug42861.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/strings/bug42861.phpt +++ php-src/ext/standard/tests/strings/bug42861.phpt --TEST-- Bug #42861 (strtr() crashes in Unicode mode when $from argument is empty) --FILE-- <?php var_dump( strtr("hello", array("" => "string") ) ); var_dump( strtr("hello", array('' => "string") ) ); var_dump( strtr("hello", array(null => "string") ) ); var_dump( strtr("hello", array(NULL => "string") ) ); var_dump( strtr("hello", "", "string") ); var_dump( strtr("hello", '', "string") ); var_dump( strtr("hello", NULL, "string") ); var_dump( strtr("hello", null, "string") ); echo "Done\n"; ?> --EXPECTF-- bool(false) bool(false) bool(false) bool(false) string(5) "hello" string(5) "hello" string(5) "hello" string(5) "hello" Done --UEXPECTF-- unicode(5) "hello" unicode(5) "hello" unicode(5) "hello" unicode(5) "hello" unicode(5) "hello" unicode(5) "hello" unicode(5) "hello" unicode(5) "hello" Done -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php