]> granicus.if.org Git - php/commitdiff
Handle mb_str(r)ipos offset consistently as well
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 24 Jan 2020 09:54:20 +0000 (10:54 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 24 Jan 2020 09:54:20 +0000 (10:54 +0100)
ext/mbstring/mbstring.c
ext/mbstring/tests/bug45923.phpt
ext/mbstring/tests/mb_strpos_offset_errors.phpt
ext/mbstring/tests/mb_strripos_empty_needle.phpt
ext/mbstring/tests/mb_strripos_variation5_Bug45923.phpt

index 3ee574db23793e039c43e684177cbc66ad1a1346..053e91e5bc89c57fa5aaefa62568774c75d0d53b 100644 (file)
@@ -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);
 
index 9f2f3c1b28029887e344e56a6ab5e02879d9a809..98428d6d30d847c9dee91c07e3f88fafac3af3f9 100644 (file)
@@ -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)
index 0a8fab3bf15ac3f9f59bf35224ded682d4d5733b..76f22431d4ff7e0caafa88962aed8b8c4abb449c 100644 (file)
@@ -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)
index 2eaf8cbe1ec1b774163d50af102b8220e30a6152..fdd873d1fb9cec23a1da037dc70d9e08df496b1d 100644 (file)
@@ -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)
index fd8f6ae22657a8dd60833e7947a515d9c445eedc..402969d6d96c9c4f26d0b8273d1e2ecca023bcba 100644 (file)
@@ -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