summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Harvey <aharvey@php.net>2012-03-02 03:39:04 +0000
committerAdam Harvey <aharvey@php.net>2012-03-02 03:39:04 +0000
commit4fc686103048c2f91867d6ce2ecbc25d29820473 (patch)
tree8a6b8901d2812d7d3716ac0bccdf0c8c2cfb0bd9
parent16748fe0fa927486e029e90b70970d4724a5a72e (diff)
downloadphp-git-4fc686103048c2f91867d6ce2ecbc25d29820473.tar.gz
MFH: Fix bug #60801 (strpbrk() mishandles NUL byte). (Trunk commit: r322934).
-rw-r--r--NEWS1
-rw-r--r--ext/standard/string.c14
-rw-r--r--ext/standard/tests/strings/bug60801.phptbin0 -> 489 bytes
3 files changed, 10 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index fc1218b93a..f7de19e0a3 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,7 @@ PHP NEWS
. Fixed bug #61000 (Exceeding max nesting level doesn't delete numerical
vars). (Laruence)
. Fixed bug #60978 (exit code incorrect). (Laruence)
+ . Fixed bug #60801 (strpbrk() mishandles NUL byte). (Adam)
. Fixed bug #60573 (type hinting with "self" keyword causes weird errors).
(Laruence)
diff --git a/ext/standard/string.c b/ext/standard/string.c
index be574109f5..0aade78085 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -5315,7 +5315,7 @@ PHP_FUNCTION(strpbrk)
{
char *haystack, *char_list;
int haystack_len, char_list_len;
- char *p;
+ char *haystack_ptr, *cl_ptr;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &haystack, &haystack_len, &char_list, &char_list_len) == FAILURE) {
RETURN_FALSE;
@@ -5326,11 +5326,15 @@ PHP_FUNCTION(strpbrk)
RETURN_FALSE;
}
- if ((p = strpbrk(haystack, char_list))) {
- RETURN_STRINGL(p, (haystack + haystack_len - p), 1);
- } else {
- RETURN_FALSE;
+ for (haystack_ptr = haystack; haystack_ptr < (haystack + haystack_len); ++haystack_ptr) {
+ for (cl_ptr = char_list; cl_ptr < (char_list + char_list_len); ++cl_ptr) {
+ if (*cl_ptr == *haystack_ptr) {
+ RETURN_STRINGL(haystack_ptr, (haystack + haystack_len - haystack_ptr), 1);
+ }
+ }
}
+
+ RETURN_FALSE;
}
/* }}} */
diff --git a/ext/standard/tests/strings/bug60801.phpt b/ext/standard/tests/strings/bug60801.phpt
new file mode 100644
index 0000000000..9587bdafa4
--- /dev/null
+++ b/ext/standard/tests/strings/bug60801.phpt
Binary files differ