]> granicus.if.org Git - php/commitdiff
fix leak in imap_utf8(), avoid extra strlen() call
authorAntony Dovgal <tony2001@php.net>
Tue, 5 Sep 2006 11:16:06 +0000 (11:16 +0000)
committerAntony Dovgal <tony2001@php.net>
Tue, 5 Sep 2006 11:16:06 +0000 (11:16 +0000)
add test

ext/imap/php_imap.c
ext/imap/tests/imap_utf8.phpt [new file with mode: 0644]

index f9a99be356ff99b28d5ab5d769344deb883eaecf..b6b9731c9e7a7c4f1ea2d9153b7235e6c9c3d982 100644 (file)
@@ -2174,7 +2174,7 @@ PHP_FUNCTION(imap_utf8)
 
        cpytxt(&src, Z_STRVAL_PP(str), Z_STRLEN_PP(str));
        utf8_mime2text(&src, &dest);
-       RETURN_STRINGL(dest.data, strlen(dest.data), 1);
+       RETURN_STRINGL(dest.data, dest.size, 0);
 }
 /* }}} */
 
diff --git a/ext/imap/tests/imap_utf8.phpt b/ext/imap/tests/imap_utf8.phpt
new file mode 100644 (file)
index 0000000..81a25c8
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+imap_utf8() tests
+--SKIPIF--
+<?php if (!extension_loaded("imap")) print "skip"; ?>
+--FILE--
+<?php
+
+var_dump(imap_utf8(""));
+var_dump(imap_utf8(1));
+var_dump(imap_utf8(array(1,2)));
+var_dump(imap_utf8("test"));
+
+echo "Done\n";
+?>
+--EXPECTF--    
+string(0) ""
+string(1) "1"
+
+Notice: Array to string conversion in %s on line %d
+string(5) "Array"
+string(4) "test"
+Done
+--UEXPECTF--
+string(0) ""
+string(1) "1"
+
+Notice: Array to string conversion in %s on line %d
+string(5) "Array"
+string(4) "test"
+Done