com php-src: Fix bug #55451: NEWS ext/standard/string.c ext/standard/tests/strings/bug55451.phpt ext/standard/tests/str ings/substr_compare.phpt

From: Date: Sun, 07 Aug 2016 16:48:36 +0000
Subject: com php-src: Fix bug #55451: NEWS ext/standard/string.c ext/standard/tests/strings/bug55451.phpt ext/standard/tests/str ings/substr_compare.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-93669@lists.php.net to get a copy of this message
Commit: e616bc8694f5a2d536462a77d629eca614626c3e Author: Lauri Kenttä <lauri.kentta@gmail.com> Wed, 3 Aug 2016 11:29:12 +0300 Committer: Nikita Popov <nikic@php.net> Sun, 7 Aug 2016 18:48:36 +0200 Parents: 56d7e98ddf8ccf18d41771482bc5434d3c615c35 Branches: PHP-7.0 PHP-7.1 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e616bc8694f5a2d536462a77d629eca614626c3e Log: 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. Bugs: https://bugs.php.net/55451 Changed paths: M NEWS M ext/standard/string.c A ext/standard/tests/strings/bug55451.phpt M ext/standard/tests/strings/substr_compare.phpt Diff: diff --git a/NEWS b/NEWS index dbcca1a..0d4ac3a 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,10 @@ PHP NEWS - Session: . Fixed bug #72724 (PHP7: session-uploadprogress kills httpd). (Nikita) +- Standard: + . Fixed bug #55451 (substr_compare NULL length interpreted as 0). (Lauri + Kenttä) + - Streams: . Fixed bug #72764 (ftps:// opendir wrapper data channel encryption fails with IIS FTP 7.5, 8.5). (vhuk) diff --git a/ext/standard/string.c b/ext/standard/string.c index 2b87791...7c456c4 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -5700,14 +5700,15 @@ PHP_FUNCTION(substr_compare) { zend_string *s1, *s2; zend_long offset, len=0; + zend_bool len_is_default=1; zend_bool cs=0; size_t cmp_len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSl|lb", &s1, &s2, &offset, &len, &cs) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSl|l!b", &s1, &s2, &offset, &len, &len_is_default, &cs) == FAILURE) { RETURN_FALSE; } - if (ZEND_NUM_ARGS() >= 4 && len <= 0) { + if (!len_is_default && len <= 0) { if (len == 0) { RETURN_LONG(0L); } else { diff --git a/ext/standard/tests/strings/bug55451.phpt b/ext/standard/tests/strings/bug55451.phpt new file mode 100644 index 0000000..4759965 --- /dev/null +++ b/ext/standard/tests/strings/bug55451.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #55451 (substr_compare with NULL as default length) +--FILE-- +<?php +var_dump(substr_compare("abcde", "ABCD", 0, NULL, false) != 0); +var_dump(substr_compare("abcde", "ABCD", 0, NULL, true) != 0); +var_dump(substr_compare("abcde", "ABCDE", 0, NULL, false) != 0); +var_dump(substr_compare("abcde", "ABCDE", 0, NULL, true) == 0); +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(true) diff --git a/ext/standard/tests/strings/substr_compare.phpt b/ext/standard/tests/strings/substr_compare.phpt index 2012fe0..c78dfca 100644 --- a/ext/standard/tests/strings/substr_compare.phpt +++ b/ext/standard/tests/strings/substr_compare.phpt @@ -39,7 +39,7 @@ Test Warning: substr_compare(): The length must be greater than or equal to zero in %s on line %d bool(false) -int(0) +int(4) Warning: substr_compare() expects parameter 4 to be integer, string given in %s on line %d bool(false)

« previous php.cvs (#93669) next »