diff --git a/NEWS b/NEWS index ed3f73aeacc..10f154298f2 100644 --- a/NEWS +++ b/NEWS @@ -32,6 +32,8 @@ PHP NEWS (Vlad Temian) . Fixed bug #77844 (Crash due to null pointer in parse_ini_string with INI_SCANNER_TYPED). (Nikita) + . Fixed bug #77853 (Inconsistent substr_compare behaviour with empty + haystack). (Nikita) 04 Apr 2019, PHP 7.2.17 diff --git a/ext/standard/string.c b/ext/standard/string.c index 1c28c6a49c7..ce90848561d 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -5739,7 +5739,7 @@ PHP_FUNCTION(substr_compare) offset = (offset < 0) ? 0 : offset; } - if ((size_t)offset >= ZSTR_LEN(s1)) { + if ((size_t)offset > ZSTR_LEN(s1)) { php_error_docref(NULL, E_WARNING, "The start position cannot exceed initial string length"); RETURN_FALSE; } diff --git a/ext/standard/tests/strings/bug77853.phpt b/ext/standard/tests/strings/bug77853.phpt new file mode 100644 index 00000000000..ad4f4c5983a --- /dev/null +++ b/ext/standard/tests/strings/bug77853.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #77853: Inconsistent substr_compare behaviour with empty haystack +--FILE-- + +--EXPECT-- +int(0) +int(0) +int(0) +int(0) +int(-1) diff --git a/ext/standard/tests/strings/substr_compare.phpt b/ext/standard/tests/strings/substr_compare.phpt index 4f69ee57c5b..a0ed6f077da 100644 --- a/ext/standard/tests/strings/substr_compare.phpt +++ b/ext/standard/tests/strings/substr_compare.phpt @@ -27,9 +27,7 @@ int(0) int(0) bool(true) bool(true) - -Warning: substr_compare(): The start position cannot exceed initial string length in %s on line %d -bool(false) +int(-1) bool(true) int(0)