summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--ext/standard/string.c2
-rw-r--r--ext/standard/tests/strings/bug39032.phpt18
3 files changed, 20 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 4e696cacbf..0587f7b957 100644
--- 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).
diff --git a/ext/standard/string.c b/ext/standard/string.c
index ee1cdbb845..759528a232 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -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
index 0000000000..dbd39ec9d8
--- /dev/null
+++ b/ext/standard/tests/strings/bug39032.phpt
@@ -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