Skip to content

Commit 0e1ab41

Browse files
committed
Fixed a bug in zend_memnistr
add test GH-12457
1 parent ef91794 commit 0e1ab41

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Zend/tests/gh12457.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
GH-12458 (Fix GH-12457: Fixed a bug in zend_memnistr)
3+
--FILE--
4+
<?php
5+
var_dump(stripos('aaBBBBBb', 'b'));
6+
var_dump(stripos('aaBBBBBbb', 'b'));
7+
var_dump(stripos('aaBBBBBbbb', 'b'));
8+
?>
9+
--EXPECTF--
10+
int(2)
11+
int(2)
12+
int(2)

Zend/zend_operators.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ zend_memnistr(const char *haystack, const char *needle, size_t needle_len, const
945945
const char *p_upper = NULL;
946946
if (first_lower != first_upper) {
947947
// If the needle length is 1 we don't need to look beyond p_lower as it is a guaranteed match
948-
size_t upper_search_length = end - (needle_len == 1 && p_lower != NULL ? p_lower : haystack);
948+
size_t upper_search_length = needle_len == 1 && p_lower != NULL ? end - haystack : p_lower - haystack;
949949
p_upper = (const char *)memchr(haystack, first_upper, upper_search_length);
950950
}
951951
const char *p = !p_upper || (p_lower && p_lower < p_upper) ? p_lower : p_upper;

0 commit comments

Comments
 (0)