From d8648eae57547a1e70461a1089e982eaa10a932f Mon Sep 17 00:00:00 2001 From: Antony Dovgal Date: Wed, 4 Oct 2006 11:14:32 +0000 Subject: [PATCH] MFH: fix #39032 (strcspn() stops on null character) --- NEWS | 1 + ext/standard/string.c | 2 +- ext/standard/tests/strings/bug39032.phpt | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/strings/bug39032.phpt 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-- + +--EXPECTF-- +int(1) +int(0) +int(1) +int(1) +Done -- 2.40.0