From: Nikita Popov Date: Fri, 24 Jan 2020 09:54:20 +0000 (+0100) Subject: Handle mb_str(r)ipos offset consistently as well X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9e0e8d5650b6b810849c2fe6cce353ae150b1429;p=php Handle mb_str(r)ipos offset consistently as well --- diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 3ee574db23..053e91e5bc 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -2171,6 +2171,7 @@ PHP_FUNCTION(mb_stripos) if (!mbfl_is_error(n)) { RETVAL_LONG(n); } else { + handle_strpos_error(n); RETVAL_FALSE; } } @@ -2194,6 +2195,7 @@ PHP_FUNCTION(mb_strripos) if (!mbfl_is_error(n)) { RETVAL_LONG(n); } else { + handle_strpos_error(n); RETVAL_FALSE; } } @@ -4811,26 +4813,6 @@ MBSTRING_API size_t php_mb_stripos(int mode, const char *old_haystack, size_t ol break; } - if (offset != 0) { - size_t haystack_char_len = mbfl_strlen(&haystack); - - if (mode) { - if ((offset > 0 && (size_t)offset > haystack_char_len) || - (offset < 0 && (size_t)(-offset) > haystack_char_len)) { - php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string"); - break; - } - } else { - if (offset < 0) { - offset += (zend_long)haystack_char_len; - } - if (offset < 0 || (size_t)offset > haystack_char_len) { - php_error_docref(NULL, E_WARNING, "Offset not contained in string"); - break; - } - } - } - n = mbfl_strpos(&haystack, &needle, offset, mode); } while(0); diff --git a/ext/mbstring/tests/bug45923.phpt b/ext/mbstring/tests/bug45923.phpt index 9f2f3c1b28..98428d6d30 100644 --- a/ext/mbstring/tests/bug45923.phpt +++ b/ext/mbstring/tests/bug45923.phpt @@ -218,7 +218,7 @@ bool(false) bool(false) > Offset: 12 -Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d +Warning: mb_strripos(): Offset not contained in string in %s on line %d bool(false) > Offset: -1 int(8) @@ -228,5 +228,5 @@ int(8) int(4) > Offset: -20 -Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d +Warning: mb_strripos(): Offset not contained in string in %s on line %d bool(false) diff --git a/ext/mbstring/tests/mb_strpos_offset_errors.phpt b/ext/mbstring/tests/mb_strpos_offset_errors.phpt index 0a8fab3bf1..76f22431d4 100644 --- a/ext/mbstring/tests/mb_strpos_offset_errors.phpt +++ b/ext/mbstring/tests/mb_strpos_offset_errors.phpt @@ -32,8 +32,8 @@ bool(false) Warning: mb_stripos(): Offset not contained in string in %s on line %d bool(false) -Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d +Warning: mb_strripos(): Offset not contained in string in %s on line %d bool(false) -Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d +Warning: mb_strripos(): Offset not contained in string in %s on line %d bool(false) diff --git a/ext/mbstring/tests/mb_strripos_empty_needle.phpt b/ext/mbstring/tests/mb_strripos_empty_needle.phpt index 2eaf8cbe1e..fdd873d1fb 100644 --- a/ext/mbstring/tests/mb_strripos_empty_needle.phpt +++ b/ext/mbstring/tests/mb_strripos_empty_needle.phpt @@ -58,12 +58,12 @@ int(5) -- ASCII string with out of bound positive offset -- -Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d +Warning: mb_strripos(): Offset not contained in string in %s on line %d bool(false) -- ASCII string with out of bound negative offset -- -Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d +Warning: mb_strripos(): Offset not contained in string in %s on line %d bool(false) -- Multi-byte string without offset -- @@ -77,10 +77,10 @@ int(19) -- Multi-byte string with out of bound positive offset -- -Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d +Warning: mb_strripos(): Offset not contained in string in %s on line %d bool(false) -- Multi-byte string with out of bound negative offset -- -Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d +Warning: mb_strripos(): Offset not contained in string in %s on line %d bool(false) diff --git a/ext/mbstring/tests/mb_strripos_variation5_Bug45923.phpt b/ext/mbstring/tests/mb_strripos_variation5_Bug45923.phpt index fd8f6ae226..402969d6d9 100644 --- a/ext/mbstring/tests/mb_strripos_variation5_Bug45923.phpt +++ b/ext/mbstring/tests/mb_strripos_variation5_Bug45923.phpt @@ -74,40 +74,40 @@ int(20) **-- Offset is: 30 --** -- ASCII String -- -Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d +Warning: mb_strripos(): Offset not contained in string in %s on line %d bool(false) --Multibyte String -- -Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d +Warning: mb_strripos(): Offset not contained in string in %s on line %d bool(false) **-- Offset is: 40 --** -- ASCII String -- -Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d +Warning: mb_strripos(): Offset not contained in string in %s on line %d bool(false) --Multibyte String -- -Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d +Warning: mb_strripos(): Offset not contained in string in %s on line %d bool(false) **-- Offset is: 50 --** -- ASCII String -- -Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d +Warning: mb_strripos(): Offset not contained in string in %s on line %d bool(false) --Multibyte String -- -Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d +Warning: mb_strripos(): Offset not contained in string in %s on line %d bool(false) **-- Offset is: 60 --** -- ASCII String -- -Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d +Warning: mb_strripos(): Offset not contained in string in %s on line %d bool(false) --Multibyte String -- -Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d +Warning: mb_strripos(): Offset not contained in string in %s on line %d bool(false) Done