Skip to content

Commit

Permalink
MFH: Fix bug #60801 (strpbrk() mishandles NUL byte). (Trunk commit: r…
Browse files Browse the repository at this point in the history
…322934).
  • Loading branch information
LawnGnome committed Mar 2, 2012
1 parent 16748fe commit 4fc6861
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 9 additions & 5 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
/* }}} */

Expand Down
Binary file added ext/standard/tests/strings/bug60801.phpt
Binary file not shown.

0 comments on commit 4fc6861

Please sign in to comment.