Skip to content

Commit e616bc8

Browse files
Metabolixnikic
authored andcommitted
Fix bug #55451
Make substr_compare ignore the length if it's NULL. This allows to use the last parameter (case_insensitivity) with the default length.
1 parent 56d7e98 commit e616bc8

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ PHP NEWS
1616
- Session:
1717
. Fixed bug #72724 (PHP7: session-uploadprogress kills httpd). (Nikita)
1818

19+
- Standard:
20+
. Fixed bug #55451 (substr_compare NULL length interpreted as 0). (Lauri
21+
Kenttä)
22+
1923
- Streams:
2024
. Fixed bug #72764 (ftps:// opendir wrapper data channel encryption fails
2125
with IIS FTP 7.5, 8.5). (vhuk)

ext/standard/string.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5700,14 +5700,15 @@ PHP_FUNCTION(substr_compare)
57005700
{
57015701
zend_string *s1, *s2;
57025702
zend_long offset, len=0;
5703+
zend_bool len_is_default=1;
57035704
zend_bool cs=0;
57045705
size_t cmp_len;
57055706

5706-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSl|lb", &s1, &s2, &offset, &len, &cs) == FAILURE) {
5707+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSl|l!b", &s1, &s2, &offset, &len, &len_is_default, &cs) == FAILURE) {
57075708
RETURN_FALSE;
57085709
}
57095710

5710-
if (ZEND_NUM_ARGS() >= 4 && len <= 0) {
5711+
if (!len_is_default && len <= 0) {
57115712
if (len == 0) {
57125713
RETURN_LONG(0L);
57135714
} else {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #55451 (substr_compare with NULL as default length)
3+
--FILE--
4+
<?php
5+
var_dump(substr_compare("abcde", "ABCD", 0, NULL, false) != 0);
6+
var_dump(substr_compare("abcde", "ABCD", 0, NULL, true) != 0);
7+
var_dump(substr_compare("abcde", "ABCDE", 0, NULL, false) != 0);
8+
var_dump(substr_compare("abcde", "ABCDE", 0, NULL, true) == 0);
9+
?>
10+
--EXPECT--
11+
bool(true)
12+
bool(true)
13+
bool(true)
14+
bool(true)

ext/standard/tests/strings/substr_compare.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Test
3939

4040
Warning: substr_compare(): The length must be greater than or equal to zero in %s on line %d
4141
bool(false)
42-
int(0)
42+
int(4)
4343

4444
Warning: substr_compare() expects parameter 4 to be integer, string given in %s on line %d
4545
bool(false)

0 commit comments

Comments
 (0)