Merge branch 'PHP-5.5' into PHP-5.6

* PHP-5.5:
  substr_compare(): Allow zero length comparison
This commit is contained in:
Tjerk Meesters 2014-02-28 23:48:34 +08:00
commit e424049840
3 changed files with 11 additions and 11 deletions

View file

@ -5585,14 +5585,13 @@ PHP_FUNCTION(substr_compare)
int s1_len, s2_len; int s1_len, s2_len;
long offset, len=0; long offset, len=0;
zend_bool cs=0; zend_bool cs=0;
uint cmp_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl|lb", &s1, &s1_len, &s2, &s2_len, &offset, &len, &cs) == FAILURE) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl|lb", &s1, &s1_len, &s2, &s2_len, &offset, &len, &cs) == FAILURE) {
RETURN_FALSE; RETURN_FALSE;
} }
if (ZEND_NUM_ARGS() >= 4 && len <= 0) { if (ZEND_NUM_ARGS() >= 4 && len < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The length must be greater than zero"); php_error_docref(NULL TSRMLS_CC, E_WARNING, "The length must be greater than or equal to zero");
RETURN_FALSE; RETURN_FALSE;
} }
@ -5606,12 +5605,10 @@ PHP_FUNCTION(substr_compare)
RETURN_FALSE; RETURN_FALSE;
} }
cmp_len = (uint) (len ? len : MAX(s2_len, (s1_len - offset)));
if (!cs) { if (!cs) {
RETURN_LONG(zend_binary_strncmp(s1 + offset, (s1_len - offset), s2, s2_len, cmp_len)); RETURN_LONG(zend_binary_strncmp(s1 + offset, (s1_len - offset), s2, s2_len, (uint)len));
} else { } else {
RETURN_LONG(zend_binary_strncasecmp_l(s1 + offset, (s1_len - offset), s2, s2_len, cmp_len)); RETURN_LONG(zend_binary_strncasecmp_l(s1 + offset, (s1_len - offset), s2, s2_len, (uint)len));
} }
} }
/* }}} */ /* }}} */

View file

@ -2,10 +2,10 @@
Bug #33605 (substr_compare crashes) Bug #33605 (substr_compare crashes)
--FILE-- --FILE--
<?php <?php
$res = substr_compare("aa", "a", -99999999, 0, 0); $res = substr_compare("aa", "a", -99999999, -1, 0);
var_dump($res); var_dump($res);
?> ?>
--EXPECTF-- --EXPECTF--
Warning: substr_compare(): The length must be greater than zero in %s on line %d Warning: substr_compare(): The length must be greater than or equal to zero in %s on line %d
bool(false) bool(false)

View file

@ -10,9 +10,10 @@ var_dump(substr_compare("abcde", "bc", 1, 3));
var_dump(substr_compare("abcde", "cd", 1, 2)); var_dump(substr_compare("abcde", "cd", 1, 2));
var_dump(substr_compare("abcde", "abc", 5, 1)); var_dump(substr_compare("abcde", "abc", 5, 1));
var_dump(substr_compare("abcde", "abcdef", -10, 10)); var_dump(substr_compare("abcde", "abcdef", -10, 10));
var_dump(substr_compare("abcde", "abc", 0, 0));
var_dump(substr_compare("abcde", -1, 0, NULL, new stdClass)); var_dump(substr_compare("abcde", -1, 0, NULL, new stdClass));
echo "Test\n"; echo "Test\n";
var_dump(substr_compare("abcde", "abc", 0, -1));
var_dump(substr_compare("abcde", "abc", -1, NULL, -5)); var_dump(substr_compare("abcde", "abc", -1, NULL, -5));
var_dump(substr_compare("abcde", -1, 0, "str", new stdClass)); var_dump(substr_compare("abcde", -1, 0, "str", new stdClass));
@ -28,13 +29,15 @@ int(-1)
Warning: substr_compare(): The start position cannot exceed initial string length in %s on line %d Warning: substr_compare(): The start position cannot exceed initial string length in %s on line %d
bool(false) bool(false)
int(-1) int(-1)
int(0)
Warning: substr_compare() expects parameter 5 to be boolean, object given in %s on line %d Warning: substr_compare() expects parameter 5 to be boolean, object given in %s on line %d
bool(false) bool(false)
Test Test
Warning: substr_compare(): The length must be greater than zero in %s on line %d Warning: substr_compare(): The length must be greater than or equal to zero in %s on line %d
bool(false) bool(false)
int(0)
Warning: substr_compare() expects parameter 4 to be long, string given in %s on line %d Warning: substr_compare() expects parameter 4 to be long, string given in %s on line %d
bool(false) bool(false)