]> 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 c8d14cbdffa3279067c3e28c01d29656a1c60ecb..c382690be398c98c4adbb66b786a9053cc189965 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,7 @@ PHP                                                                        NEWS
     functions). (Pierre)
   . Fixed bug #60825 (Segfault when running symfony 2 tests).
     (Dmitry, Laruence)
+  . Fixed bug #60801 (strpbrk() mishandles NUL byte). (Adam)
   . Fixed bug #60227 (header() cannot detect the multi-line header with CR).
     (rui, Gustavo)
   . Fixed bug #51860 (Include fails with toplevel symlink to /). (Dmitry)
index 56c9d48e9443cb89a3d3423f83a5232f5885f846..e3fc27e7e2245e7e59bda38ece8d0255d8ca8e59 100644 (file)
@@ -5240,7 +5240,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;
@@ -5251,11 +5251,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