php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length should be greater than 0.");
RETURN_FALSE;
}
- if ((p + Z_LVAL_PP(length)) <= p || (p + Z_LVAL_PP(length)) > endp) {
+ if (Z_LVAL_PP(length) > (Z_STRLEN_PP(haystack) - Z_LVAL_PP(offset))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length value %ld exceeds string length.", Z_LVAL_PP(length));
RETURN_FALSE;
}
offset = (offset < 0) ? 0 : offset;
}
- if ((offset + len) > s1_len || (offset+len) < 0) {
+ if(offset > s1_len) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The start position cannot exceed initial string length");
RETURN_FALSE;
}
+ if(len > s1_len - offset) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "The length cannot exceed initial string length");
+ RETURN_FALSE;
+ }
+
cmp_len = (uint) (len ? len : MAX(s2_len, (s1_len - offset)));
if (!cs) {