]> granicus.if.org Git - php/commitdiff
Fixed bug #54454 (substr_compare incorrectly reports equality in some cases)
authorPierrick Charron <pierrick@php.net>
Sun, 3 Apr 2011 07:18:27 +0000 (07:18 +0000)
committerPierrick Charron <pierrick@php.net>
Sun, 3 Apr 2011 07:18:27 +0000 (07:18 +0000)
NEWS
ext/standard/string.c
ext/standard/tests/strings/bug54454.phpt [new file with mode: 0644]
ext/standard/tests/strings/substr_compare.phpt

diff --git a/NEWS b/NEWS
index 463e765cd50fdbf7b6987e5cd8fddbd7528650e8..1ca5022ce723dd604b87c024188774697b3a0310 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,10 +9,13 @@ PHP                                                                        NEWS
 
 - Core:
   . Fixed a crash inside dtor for error handling. (Ilia)
+  . Fixed bug #54454 (substr_compare incorrectly reports equality in some 
+    cases). (Pierrick)
   . Fixed bug #54180 (parse_url() incorrectly parses path when ? in fragment).
     (tomas dot brastavicius at quantum dot lt, Pierrick)
-   . Fixed bug #48465 (sys_get_temp_dir() possibly inconsistent when using 
-     TMPDIR on Windows). (Pierre)
+  . Fixed bug #48465 (sys_get_temp_dir() possibly inconsistent when using 
+    TMPDIR on Windows). (Pierre)
+
 - cURL
   . Added CURLINFO_REDIRECT_URL support. (Daniel Stenberg, Pierre)
 
index 7208d8677981e323131ff8dfabde08412fe6fce9..9dd99cefa20b815c8cdd50bb18a4e76faba21b10 100644 (file)
@@ -5243,10 +5243,6 @@ PHP_FUNCTION(substr_compare)
                RETURN_FALSE;
        }
 
-       if (len > s1_len - offset) {
-               len = s1_len - offset;
-       }
-
        cmp_len = (uint) (len ? len : MAX(s2_len, (s1_len - offset)));
 
        if (!cs) {
diff --git a/ext/standard/tests/strings/bug54454.phpt b/ext/standard/tests/strings/bug54454.phpt
new file mode 100644 (file)
index 0000000..88835c9
--- /dev/null
@@ -0,0 +1,8 @@
+--TEST--
+Bug #54454 (substr_compare incorrectly reports equality in some cases)
+--FILE--
+<?php
+var_dump(substr_compare('/', '/asd', 0, 4));
+?>
+--EXPECT--
+int(-3)
index 206ccd5edea0183f99f317d599e40a7f2c7ac943..c647506b53736a7ee244e1e98127aa9f9fccb1ab 100644 (file)
@@ -27,7 +27,7 @@ int(-1)
 
 Warning: substr_compare(): The start position cannot exceed initial string length in %s on line %d
 bool(false)
-int(0)
+int(-1)
 
 Warning: substr_compare() expects parameter 5 to be boolean, object given in %s on line %d
 bool(false)