com php-src: Fix #72320: iconv_substr returns false for empty strings: ext/iconv/iconv.c ext/iconv/tests/b ug72320.phpt

From: Date: Fri, 29 Jul 2016 09:33:50 +0000
Subject: com php-src: Fix #72320: iconv_substr returns false for empty strings: ext/iconv/iconv.c ext/iconv/tests/b ug72320.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-94141@lists.php.net to get a copy of this message
Commit: a837b2f6a35ab7cdfb49b9407ac0401caa672b23 Author: Christoph M. Becker <cmb@php.net> Fri, 29 Jul 2016 11:28:33 +0200 Committer: Christoph M. Becker <cmbecker69@gmx.de> Fri, 29 Jul 2016 11:33:50 +0200 Parents: 293dd3d7017e3df8f06898d3a7d1c00eb935ee0c Branches: PHP-7.0 PHP-7.1 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a837b2f6a35ab7cdfb49b9407ac0401caa672b23 Log: Fix #72320: iconv_substr returns false for empty strings For consistency with substr() and mb_substr(), iconv_substr() should return an empty string instead of FALSE, when $offset == iconv_strlen($str). Bugs: https://bugs.php.net/72320 Changed paths: M ext/iconv/iconv.c A ext/iconv/tests/bug72320.phpt Diff: diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index d4a7f6e..3648823 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -858,7 +858,7 @@ static php_iconv_err_t _php_iconv_substr(smart_str *pretval, } - if ((size_t)offset >= total_len) { + if ((size_t)offset > total_len) { return PHP_ICONV_ERR_SUCCESS; } @@ -2108,7 +2108,7 @@ PHP_FUNCTION(iconv_substr) err = _php_iconv_substr(&retval, ZSTR_VAL(str), ZSTR_LEN(str), offset, length, charset); _php_iconv_show_error(err, GENERIC_SUPERSET_NAME, charset); - if (err == PHP_ICONV_ERR_SUCCESS && ZSTR_LEN(str) > 0 && retval.s != NULL) { + if (err == PHP_ICONV_ERR_SUCCESS && ZSTR_LEN(str) >= 0 && retval.s != NULL) { RETURN_NEW_STR(retval.s); } smart_str_free(&retval); diff --git a/ext/iconv/tests/bug72320.phpt b/ext/iconv/tests/bug72320.phpt new file mode 100644 index 0000000..0c83d33 --- /dev/null +++ b/ext/iconv/tests/bug72320.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #72320 (iconv_substr returns false for empty strings) +--SKIPIF-- +<?php +if (!extension_loaded('iconv')) die('skip ext/iconv required'); +?> +--FILE-- +<?php +var_dump(iconv_substr('', 0, 10, 'UTF-8')); +var_dump(iconv_substr('foo', 3, 10, 'UTF-8')); +?> +--EXPECT-- +string(0) "" +string(0) ""

« previous php.cvs (#94141) next »