Skip to content

Commit

Permalink
Fixed bug #77853
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Apr 8, 2019
1 parent eea61cd commit d7b5954
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
20 changes: 20 additions & 0 deletions ext/standard/tests/strings/bug77853.phpt
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 1 addition & 3 deletions ext/standard/tests/strings/substr_compare.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit d7b5954

Please sign in to comment.