]> granicus.if.org Git - php/commitdiff
MFH: fix #39032 (strcspn() stops on null character)
authorAntony Dovgal <tony2001@php.net>
Wed, 4 Oct 2006 11:14:32 +0000 (11:14 +0000)
committerAntony Dovgal <tony2001@php.net>
Wed, 4 Oct 2006 11:14:32 +0000 (11:14 +0000)
NEWS
ext/standard/string.c
ext/standard/tests/strings/bug39032.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 4e696cacbf5a998f4fe7dd89332d5e37c07ae428..0587f7b957bcbac3fdf910ee8650fb0abeea8318 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ PHP                                                                        NEWS
 - Fixed mess with CGI/CLI -d option (now it works with cgi; constants are
   working exactly like in php.ini; with FastCGI -d affects all requests).
   (Dmitry)
+- Fixed bug #39032 (strcspn() stops on null character). (Tony)
 - Fixed bug #39017 (foreach(($obj = new myClass) as $v); echo $obj; segfaults).
   (Dmitry)
 - Fixed bug #39004 (Fixed generation of config.nice with autoconf 2.60).
index ee1cdbb845496f597b7c86150e3e60216f0f0065..759528a232d3906916b9938a8eb7fdbb7e726c14 100644 (file)
@@ -1500,7 +1500,7 @@ PHPAPI size_t php_strcspn(char *s1, char *s2, char *s1_end, char *s2_end)
                        if (*spanp == c || p == s1_end) {
                                return p - s1;
                        }
-               } while (spanp++ < s2_end);
+               } while (spanp++ < (s2_end - 1));
                c = *++p;
        }
        /* NOTREACHED */
diff --git a/ext/standard/tests/strings/bug39032.phpt b/ext/standard/tests/strings/bug39032.phpt
new file mode 100644 (file)
index 0000000..dbd39ec
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Bug #39032 (strcspn() stops on null character)
+--FILE--
+<?php
+
+var_dump(strcspn(chr(0),"x"));
+var_dump(strcspn(chr(0),""));
+var_dump(strcspn(chr(0),"qweqwe"));
+var_dump(strcspn(chr(1),"qweqwe"));
+
+echo "Done\n";
+?>
+--EXPECTF--    
+int(1)
+int(0)
+int(1)
+int(1)
+Done