aharvey                                  Fri, 02 Mar 2012 03:39:04 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=323779

Log:
MFH: Fix bug #60801 (strpbrk() mishandles NUL byte). (Trunk commit: r322934).

Bug: https://bugs.php.net/60801 (Closed) strpbrk() mishandles NUL byte
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/standard/string.c
    A   php/php-src/branches/PHP_5_3/ext/standard/tests/strings/bug60801.phpt
    U   php/php-src/branches/PHP_5_4/NEWS
    U   php/php-src/branches/PHP_5_4/ext/standard/string.c
    A   php/php-src/branches/PHP_5_4/ext/standard/tests/strings/bug60801.phpt

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS   2012-03-02 03:38:04 UTC (rev 323778)
+++ php/php-src/branches/PHP_5_3/NEWS   2012-03-02 03:39:04 UTC (rev 323779)
@@ -18,6 +18,7 @@
     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)

Modified: php/php-src/branches/PHP_5_3/ext/standard/string.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/string.c  2012-03-02 03:38:04 UTC 
(rev 323778)
+++ php/php-src/branches/PHP_5_3/ext/standard/string.c  2012-03-02 03:39:04 UTC 
(rev 323779)
@@ -5240,7 +5240,7 @@
 {
        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 @@
                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;
 }
 /* }}} */


Added: php/php-src/branches/PHP_5_3/ext/standard/tests/strings/bug60801.phpt
===================================================================
(Binary files differ)


Property changes on: 
php/php-src/branches/PHP_5_3/ext/standard/tests/strings/bug60801.phpt
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: php/php-src/branches/PHP_5_4/NEWS
===================================================================
--- php/php-src/branches/PHP_5_4/NEWS   2012-03-02 03:38:04 UTC (rev 323778)
+++ php/php-src/branches/PHP_5_4/NEWS   2012-03-02 03:39:04 UTC (rev 323779)
@@ -15,6 +15,7 @@
   . 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)


Modified: php/php-src/branches/PHP_5_4/ext/standard/string.c
===================================================================
--- php/php-src/branches/PHP_5_4/ext/standard/string.c  2012-03-02 03:38:04 UTC 
(rev 323778)
+++ php/php-src/branches/PHP_5_4/ext/standard/string.c  2012-03-02 03:39:04 UTC 
(rev 323779)
@@ -5315,7 +5315,7 @@
 {
        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 @@
                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;
 }
 /* }}} */


Added: php/php-src/branches/PHP_5_4/ext/standard/tests/strings/bug60801.phpt
===================================================================
(Binary files differ)


Property changes on: 
php/php-src/branches/PHP_5_4/ext/standard/tests/strings/bug60801.phpt
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to