From: Adam Harvey Date: Fri, 2 Mar 2012 03:39:04 +0000 (+0000) Subject: MFH: Fix bug #60801 (strpbrk() mishandles NUL byte). (Trunk commit: r322934). X-Git-Tag: PHP-5.4.1-RC1~108 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4fc686103048c2f91867d6ce2ecbc25d29820473;p=php MFH: Fix bug #60801 (strpbrk() mishandles NUL byte). (Trunk commit: r322934). --- 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 Binary files /dev/null and b/ext/standard/tests/strings/bug60801.phpt differ