]> granicus.if.org Git - php/commitdiff
Fixed bug #62070
authorGustavo André dos Santos Lopes <cataphract@php.net>
Wed, 23 May 2012 11:22:06 +0000 (13:22 +0200)
committerGustavo André dos Santos Lopes <cataphract@php.net>
Wed, 23 May 2012 11:25:32 +0000 (13:25 +0200)
Collator::getSortKey() was returning an unterminated string
due the length given to RETURN_STRINGL being off by one.

ext/intl/collator/collator_sort.c
ext/intl/tests/bug62070.phpt [new file with mode: 0644]

index a871c90a8ea4160e348304142e1145ad615d5038..0785111c964b476da2c1d169bad65f0ab1048fa9 100755 (executable)
@@ -594,6 +594,8 @@ PHP_FUNCTION( collator_get_sort_key )
                RETURN_FALSE;
        }
 
+       /* ucol_getSortKey is exception in that the key length includes the 
+        * NUL terminator*/
        key_len = ucol_getSortKey(co->ucoll, ustr, ustr_len, key, 0);
        if(!key_len) {
                efree( ustr );
@@ -605,7 +607,7 @@ PHP_FUNCTION( collator_get_sort_key )
        if(!key_len) {
                RETURN_FALSE;
        }
-       RETURN_STRINGL((char *)key, key_len, 0);
+       RETURN_STRINGL((char *)key, key_len - 1, 0);
 }
 /* }}} */
 
diff --git a/ext/intl/tests/bug62070.phpt b/ext/intl/tests/bug62070.phpt
new file mode 100644 (file)
index 0000000..a466b05
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+Bug #62070: Collator::getSortKey() returns garbage
+--SKIPIF--
+<?php
+if (!extension_loaded('intl'))
+       die('skip intl extension not enabled');
+--FILE--
+<?php
+$s1 = 'Hello';
+
+$coll = collator_create('en_US');
+$res = collator_get_sort_key($coll, $s1);
+
+echo urlencode($res);
+--EXPECT--
+5%2F%3D%3DC%01%09%01%8F%08