diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-08 11:40:50 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-08 11:40:50 +0200 |
commit | d7b5954f2818aff6db29a995f407797a7902f38f (patch) | |
tree | 87e5b82cf42a8b8809580b84db418983f33bd07b /ext/standard | |
parent | eea61cda7df1466a1f40a17c21b65901c1c68ce0 (diff) | |
download | php-git-d7b5954f2818aff6db29a995f407797a7902f38f.tar.gz |
Fixed bug #77853
Diffstat (limited to 'ext/standard')
-rw-r--r-- | ext/standard/string.c | 2 | ||||
-rw-r--r-- | ext/standard/tests/strings/bug77853.phpt | 20 | ||||
-rw-r--r-- | ext/standard/tests/strings/substr_compare.phpt | 4 |
3 files changed, 22 insertions, 4 deletions
diff --git a/ext/standard/string.c b/ext/standard/string.c index 1c28c6a49c..ce90848561 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 0000000000..ad4f4c5983 --- /dev/null +++ b/ext/standard/tests/strings/bug77853.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #77853: Inconsistent substr_compare behaviour with empty haystack +--FILE-- +<?php + +var_dump(substr_compare('', '', 0, 0)); +var_dump(substr_compare('', '', 0)); + +var_dump(substr_compare('abc', '', 3, 0)); +var_dump(substr_compare('abc', '', 3)); + +var_dump(substr_compare('abc', "\0", 3)); + +?> +--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 4f69ee57c5..a0ed6f077d 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) |