]> granicus.if.org Git - php/commitdiff
- Fixed bug #52211 (iconv() returns part of string on error)
authorFelipe Pena <felipe@php.net>
Thu, 1 Jul 2010 01:11:08 +0000 (01:11 +0000)
committerFelipe Pena <felipe@php.net>
Thu, 1 Jul 2010 01:11:08 +0000 (01:11 +0000)
NEWS
ext/iconv/iconv.c
ext/iconv/tests/bug52211.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 698d8ae537dfd34b1bf2dfc22a1aa2c50b38bd79..df2686a6a081b4968da85b56fe8c255e59b651ab 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -85,6 +85,8 @@
 
 - Fixed PDO objects binary incompatibility. (Dmitry)
 
+- Fixed bug #52211 (iconv() returns part of string on error). (Felipe)
+
        
 ?? ??? 20??, PHP 5.3.3
 - Upgraded bundled PCRE to version 8.01. (Ilia)
index 07fb359a2b1cb615e7c86be6c1648e6fd8523046..40a03529bf4b4ed02af5e5334bb0e84c8c995436 100644 (file)
@@ -2357,9 +2357,12 @@ PHP_NAMED_FUNCTION(php_if_iconv)
        err = php_iconv_string(in_buffer, (size_t)in_buffer_len,
                &out_buffer, &out_len, out_charset, in_charset);
        _php_iconv_show_error(err, out_charset, in_charset TSRMLS_CC); 
-       if (out_buffer != NULL) {
+       if (err == PHP_ICONV_ERR_SUCCESS && out_buffer != NULL) {
                RETVAL_STRINGL(out_buffer, out_len, 0);
        } else {
+               if (out_buffer != NULL) {
+                       efree(out_buffer);
+               }
                RETURN_FALSE;
        }
 }
diff --git a/ext/iconv/tests/bug52211.phpt b/ext/iconv/tests/bug52211.phpt
new file mode 100644 (file)
index 0000000..152aab8
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Bug #52211 (iconv() returns part of string on error)
+--FILE--
+<?php
+
+$str = "PATHOLOGIES MÉDICO-CHIRUR. ADUL. PL";
+$str_iconv = iconv('CP850', 'ISO-8859-1', $str );
+var_dump($str_iconv);
+
+?>
+--EXPECTF--
+Notice: iconv(): Detected an illegal character in input string in %s on line %d
+bool(false)