diff options
author | Christoph M. Becker <cmb@php.net> | 2016-07-28 15:21:48 +0200 |
---|---|---|
committer | Christoph M. Becker <cmb@php.net> | 2016-07-28 15:21:48 +0200 |
commit | ee6900c3de68f1b94dfae8e230c7fa755c7fa595 (patch) | |
tree | 230f66edfe04dfa13b0172ef4ae1a32567913c90 | |
parent | 56cdaecb284b2b292ce1ecb076c1f8b041e47a02 (diff) | |
download | php-git-ee6900c3de68f1b94dfae8e230c7fa755c7fa595.tar.gz |
Fix #72694: mb_ereg_search_setpos does not accept a string's last position
Setting the search position immediately behind the last character should be
allowed, so we fix this off-by-one error.
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | ext/mbstring/php_mbregex.c | 2 | ||||
-rw-r--r-- | ext/mbstring/tests/bug72694.phpt | 21 |
3 files changed, 25 insertions, 2 deletions
@@ -44,8 +44,10 @@ PHP NEWS - mbstring: . Fixed bug #72691 (mb_ereg_search raises a warning if a match zero-width). (cmb) - . Fixed Bug #72693 (mb_ereg_search increments search position when a match + . Fixed bug #72693 (mb_ereg_search increments search position when a match zero-width). (cmb) + . Fixed bug #72694 (mb_ereg_search_setpos does not accept a string's last + position). (cmb) - PCRE: . Fixed bug #72688 (preg_match missing group names in matches). (cmb) diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c index a295f54e4e..9873a85da1 100644 --- a/ext/mbstring/php_mbregex.c +++ b/ext/mbstring/php_mbregex.c @@ -1400,7 +1400,7 @@ PHP_FUNCTION(mb_ereg_search_setpos) return; } - if (position < 0 || (MBREX(search_str) != NULL && Z_TYPE_P(MBREX(search_str)) == IS_STRING && position >= Z_STRLEN_P(MBREX(search_str)))) { + if (position < 0 || (MBREX(search_str) != NULL && Z_TYPE_P(MBREX(search_str)) == IS_STRING && position > Z_STRLEN_P(MBREX(search_str)))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Position is out of range"); MBREX(search_pos) = 0; RETURN_FALSE; diff --git a/ext/mbstring/tests/bug72694.phpt b/ext/mbstring/tests/bug72694.phpt new file mode 100644 index 0000000000..90f56a397a --- /dev/null +++ b/ext/mbstring/tests/bug72694.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #72694 (mb_ereg_search_setpos does not accept a string's last position) +--SKIPIF-- +<?php +if (!extension_loaded('mbstring')) die('skip ext/mbstring required'); +?> +--FILE-- +<?php +mb_ereg_search_init('foo'); + +var_dump(mb_ereg_search_setpos(3)); +var_dump(mb_ereg_search_getpos()); + +var_dump(mb_ereg_search('\Z')); +var_dump(mb_ereg_search_getpos()); +?> +--EXPECT-- +bool(true) +int(3) +bool(true) +int(3) |