]> granicus.if.org Git - php/commitdiff
MFH: Fix bug #60801 (strpbrk() mishandles NUL byte). (Trunk commit: r322934).
authorAdam Harvey <aharvey@php.net>
Fri, 2 Mar 2012 03:39:04 +0000 (03:39 +0000)
committerAdam Harvey <aharvey@php.net>
Fri, 2 Mar 2012 03:39:04 +0000 (03:39 +0000)
NEWS
ext/standard/string.c
ext/standard/tests/strings/bug60801.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index fc1218b93a8c95a5d17a761c61506d03c62c3a45..f7de19e0a39cfd76313845fae57b05ff16f26193 100644 (file)
--- 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)
 
index be574109f59556396b239fe18c0de8bcc12551b1..0aade780856b9a00ba606ba77028790f6d742b13 100644 (file)
@@ -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 (file)
index 0000000..9587bda
Binary files /dev/null and b/ext/standard/tests/strings/bug60801.phpt differ