Skip to content

Commit 3fba8ce

Browse files
committed
Move out of bound offset into the switch error code handler
1 parent 5881e01 commit 3fba8ce

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

ext/mbstring/mbstring.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,17 +2100,6 @@ PHP_FUNCTION(mb_strpos)
21002100
RETURN_FALSE;
21012101
}
21022102

2103-
if (offset != 0) {
2104-
size_t slen = mbfl_strlen(&haystack);
2105-
if (offset < 0) {
2106-
offset += slen;
2107-
}
2108-
if (offset < 0 || offset > slen) {
2109-
zend_value_error("Offset not contained in string");
2110-
RETURN_THROWS();
2111-
}
2112-
}
2113-
21142103
n = mbfl_strpos(&haystack, &needle, offset, reverse);
21152104
if (!mbfl_is_error(n)) {
21162105
RETVAL_LONG(n);
@@ -2127,6 +2116,9 @@ PHP_FUNCTION(mb_strpos)
21272116
case 8:
21282117
zend_value_error("Argument is empty");
21292118
RETURN_THROWS();
2119+
case 16:
2120+
zend_value_error("Offset not contained in string");
2121+
RETURN_THROWS();
21302122
default:
21312123
zend_value_error("Unknown error in mb_strpos");
21322124
RETURN_THROWS();

0 commit comments

Comments
 (0)