[PHP-CVS] svn: /php/php-src/trunk/ext/standard/ string.c tests/strings/bug60801.phpt

2012-01-30 Thread Adam Harvey
aharvey  Mon, 30 Jan 2012 13:29:15 +

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

Log:
Fix bug #60801 (strpbrk() mishandles NUL byte) on trunk only for now.

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

Modified: php/php-src/trunk/ext/standard/string.c
===
--- php/php-src/trunk/ext/standard/string.c 2012-01-30 13:02:10 UTC (rev 
322933)
+++ php/php-src/trunk/ext/standard/string.c 2012-01-30 13:29:15 UTC (rev 
322934)
@@ -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/trunk/ext/standard/tests/strings/bug60801.phpt
===
--- php/php-src/trunk/ext/standard/tests/strings/bug60801.phpt  
(rev 0)
+++ php/php-src/trunk/ext/standard/tests/strings/bug60801.phpt  2012-01-30 
13:29:15 UTC (rev 322934)
@@ -0,0 +1,23 @@
+--TEST--
+Bug #60801 (strpbrk() mishandles NUL byte)
+--FILE--
+
+--EXPECT--
+string(2) "ar"
+string(3) "
+string(4) "b
+string(3) "bar"
+string(1) "
+bool(false)
+bool(false)


Property changes on: php/php-src/trunk/ext/standard/tests/strings/bug60801.phpt
___
Added: svn:mime-type
   + text/x-php

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

[PHP-CVS] svn: /php/php-src/trunk/ext/standard/ string.c

2012-01-20 Thread Pierrick Charron
pierrick Fri, 20 Jan 2012 13:20:14 +

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

Log:
Remove memory leak in substr_replace (to commit in 5.4 after code freeze)

Changed paths:
U   php/php-src/trunk/ext/standard/string.c

Modified: php/php-src/trunk/ext/standard/string.c
===
--- php/php-src/trunk/ext/standard/string.c 2012-01-20 12:31:37 UTC (rev 
322496)
+++ php/php-src/trunk/ext/standard/string.c 2012-01-20 13:20:14 UTC (rev 
322497)
@@ -2518,6 +2518,9 @@

if(Z_REFCOUNT_P(orig_str) != refcount) {
php_error_docref(NULL 
TSRMLS_CC, E_WARNING, "Argument was modified while replacing");
+   if(Z_TYPE_PP(tmp_repl) != 
IS_STRING) {
+   zval_dtor(repl_str);
+   }
break;
}


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

[PHP-CVS] svn: /php/php-src/trunk/ext/standard/ string.c

2010-07-19 Thread Adam Harvey
aharvey  Tue, 20 Jul 2010 04:26:57 +

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

Log:
Fix bug #52380 (Typo in lcfirst comment docs) by updating the commented
prototype for lcfirst() to actually read lcfirst().

Bug: http://bugs.php.net/52380 (Assigned) Typo in lcfirst comment docs
  
Changed paths:
U   php/php-src/trunk/ext/standard/string.c

Modified: php/php-src/trunk/ext/standard/string.c
===
--- php/php-src/trunk/ext/standard/string.c 2010-07-20 04:25:14 UTC (rev 
301411)
+++ php/php-src/trunk/ext/standard/string.c 2010-07-20 04:26:57 UTC (rev 
301412)
@@ -2571,7 +2571,7 @@
 }
 /* }}} */

-/* {{{ proto string ucfirst(string str)
+/* {{{ proto string lcfirst(string str)
Make a string's first character lowercase */
 PHP_FUNCTION(lcfirst)
 {

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

[PHP-CVS] svn: /php/php-src/trunk/ext/standard/ string.c

2009-12-16 Thread Dmitry Stogov
dmitry   Wed, 16 Dec 2009 11:15:22 +

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

Log:
Fixed str_replace() to work with both binary and unicode strings

Changed paths:
U   php/php-src/trunk/ext/standard/string.c

Modified: php/php-src/trunk/ext/standard/string.c
===
--- php/php-src/trunk/ext/standard/string.c 2009-12-16 10:49:54 UTC (rev 
292194)
+++ php/php-src/trunk/ext/standard/string.c 2009-12-16 11:15:22 UTC (rev 
292195)
@@ -5402,17 +5402,25 @@
 static void php_str_replace_in_subject(zval *search, zval *replace, zval 
**subject, zval *result, int case_sensitivity, int *replace_count TSRMLS_DC)
 {
zval**search_entry,
-   **replace_entry = NULL,
+   **replace_entry,
+*replace_value,
+ temp_replace,
  temp_result;
-   zstr replace_value = NULL_ZSTR;
-   int  replace_len = 0;

/* Make sure we're dealing with strings. */
-   convert_to_unicode_ex(subject);
-   Z_TYPE_P(result) = IS_UNICODE;
-   if (Z_UNILEN_PP(subject) == 0) {
-   ZVAL_EMPTY_UNICODE(result);
-   return;
+   if (Z_TYPE_PP(subject) == IS_STRING) {
+   Z_TYPE_P(result) = IS_STRING;
+   if (Z_UNILEN_PP(subject) == 0) {
+   ZVAL_EMPTY_STRING(result);
+   return;
+   }
+   } else {
+   convert_to_unicode_ex(subject);
+   Z_TYPE_P(result) = IS_UNICODE;
+   if (Z_UNILEN_PP(subject) == 0) {
+   ZVAL_EMPTY_UNICODE(result);
+   return;
+   }
}

/* If search is an array */
@@ -5426,15 +5434,13 @@
zend_hash_internal_pointer_reset(Z_ARRVAL_P(replace));
} else {
/* Set replacement value to the passed one */
-   replace_value = Z_UNIVAL_P(replace);
-   replace_len = Z_UNILEN_P(replace);
+   replace_value = replace;
}

/* For each entry in the search array, get the entry */
while (zend_hash_get_current_data(Z_ARRVAL_P(search), (void **) 
&search_entry) == SUCCESS) {
/* Make sure we're dealing with strings. */
SEPARATE_ZVAL(search_entry);
-   convert_to_unicode(*search_entry);
if (Z_UNILEN_PP(search_entry) == 0) {
zend_hash_move_forward(Z_ARRVAL_P(search));
if (Z_TYPE_P(replace) == IS_ARRAY) {
@@ -5447,47 +5453,23 @@
if (Z_TYPE_P(replace) == IS_ARRAY) {
/* Get current entry */
if 
(zend_hash_get_current_data(Z_ARRVAL_P(replace), (void **)&replace_entry) == 
SUCCESS) {
-   /* Make sure we're dealing with 
strings. */
SEPARATE_ZVAL(replace_entry);
-   convert_to_unicode(*replace_entry);
-
-   /* Set replacement value to the one we 
got from array */
-   replace_value = 
Z_UNIVAL_PP(replace_entry);
-   replace_len = 
Z_UNILEN_PP(replace_entry);
-
+   replace_value = *replace_entry;

zend_hash_move_forward(Z_ARRVAL_P(replace));
} else {
/* We've run out of replacement 
strings, so use an empty one. */
-   replace_value = EMPTY_ZSTR;
-   replace_len = 0;
+   replace_value = &temp_replace;
+   Z_UNILEN_P(replace_value) = 0;
+   Z_UNIVAL_P(replace_value) = EMPTY_ZSTR;
+   if (Z_TYPE_PP(subject) == IS_STRING) {
+   Z_TYPE_P(replace_value) = 
IS_STRING;
+   } else {
+   Z_TYPE_P(replace_value) = 
IS_UNICODE;
+   }
}
}

-   if (Z_UNILEN_PP(search_entry) == 1) {
-   if (case_sensitivity) {
-   
php_u_char_to_str_ex(Z_USTRVAL_P(result), Z_USTRLEN_P(result),
-

[PHP-CVS] svn: /php/php-src/trunk/ext/standard/ string.c

2009-11-24 Thread Kalle Sommer Nielsen
kalleTue, 24 Nov 2009 11:08:16 +

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

Log:
Fixed #50226 (Insufficient memory allocation for unicode string)
 - Patch by yoarvi at gmail dot com

Bug: http://bugs.php.net/50226 (Open) [PATCH] - Insufficient memory allocation 
for unicode string
  
Changed paths:
U   php/php-src/trunk/ext/standard/string.c

Modified: php/php-src/trunk/ext/standard/string.c
===
--- php/php-src/trunk/ext/standard/string.c 2009-11-24 11:02:47 UTC (rev 
291258)
+++ php/php-src/trunk/ext/standard/string.c 2009-11-24 11:08:16 UTC (rev 
291259)
@@ -3457,7 +3457,7 @@

if (type == IS_UNICODE) {
old_end.u = old.u + old_len;
-   str.u = safe_emalloc(2, UBYTES(old_len), 1);
+   str.u = safe_emalloc(2, UBYTES(old_len), UBYTES(1));

for (p.u = old.u, q.u = str.u; p.u != old_end.u; p.u++) {
cp = *p.u;

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

[PHP-CVS] svn: /php/php-src/trunk/ext/standard/ string.c

2009-08-15 Thread Felipe Pena
felipe   Sat, 15 Aug 2009 16:05:06 +

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

Log:
- Fix ZTS build && removed unused vars

Changed paths:
U   php/php-src/trunk/ext/standard/string.c

Modified: php/php-src/trunk/ext/standard/string.c
===
--- php/php-src/trunk/ext/standard/string.c 2009-08-15 15:29:01 UTC (rev 
287339)
+++ php/php-src/trunk/ext/standard/string.c 2009-08-15 16:05:06 UTC (rev 
287340)
@@ -2322,7 +2322,7 @@

 /* {{{ php_needle_char
  */
-static long php_needle_char(zval *needle)
+static long php_needle_char(zval *needle TSRMLS_DC)
 {
switch (Z_TYPE_P(needle)) {
case IS_LONG:
@@ -2351,7 +2351,7 @@
 }
 /* }}} */

-static zstr php_needle_to_type(zval **needle, zend_uchar haystack_type, int 
*target_len, char *char_buf, UChar *uchar_buf)
+static zstr php_needle_to_type(zval **needle, zend_uchar haystack_type, int 
*target_len, char *char_buf, UChar *uchar_buf TSRMLS_DC)
 {
zstr target;

@@ -2367,7 +2367,7 @@
target = Z_UNIVAL_PP(needle);
*target_len = Z_UNILEN_PP(needle);
} else {
-   long needleval = php_needle_char(*needle);
+   long needleval = php_needle_char(*needle TSRMLS_CC);
if(needleval == -1) {
return target;
}
@@ -2409,7 +2409,7 @@
return;
}

-   target = php_needle_to_type(needle, haystack_type, &needle_len, 
needle_char, u_needle_char);
+   target = php_needle_to_type(needle, haystack_type, &needle_len, 
needle_char, u_needle_char TSRMLS_CC);

if(target.v == NULL) {
RETURN_FALSE;
@@ -2465,7 +2465,7 @@
return;
}

-   target = php_needle_to_type(needle, haystack_type, &needle_len, 
needle_char, u_needle_char);
+   target = php_needle_to_type(needle, haystack_type, &needle_len, 
needle_char, u_needle_char TSRMLS_CC);

if(target.v == NULL) {
RETURN_FALSE;
@@ -2548,7 +2548,7 @@
RETURN_FALSE;
}

-   target = php_needle_to_type(needle, haystack_type, &needle_len, 
needle_char, u_needle_char);
+   target = php_needle_to_type(needle, haystack_type, &needle_len, 
needle_char, u_needle_char TSRMLS_CC);

if(target.v == NULL) {
RETURN_FALSE;
@@ -2596,7 +2596,6 @@
void *found = NULL;
long offset = 0;
char *haystack_dup = NULL, *needle_dup = NULL;
-   char c = 0;
int cu_offset = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "tZ|l", &haystack, 
&haystack_len, &haystack_type, &needle, &offset) == FAILURE) {
@@ -2617,7 +2616,7 @@
RETURN_FALSE;
}

-   target = php_needle_to_type(needle, haystack_type, &needle_len, 
needle_char, u_needle_char);
+   target = php_needle_to_type(needle, haystack_type, &needle_len, 
needle_char, u_needle_char TSRMLS_CC);

if(target.v == NULL) {
RETURN_FALSE;
@@ -2669,7 +2668,6 @@
zval **needle;
char needle_char[2];
UChar u_needle_char[3];
-   void *found = NULL;
long offset = 0;
char *p, *e;
UChar *pos, *u_p, *u_e;
@@ -2679,7 +2677,7 @@
return;
}

-   target = php_needle_to_type(needle, haystack_type, &needle_len, 
needle_char, u_needle_char);
+   target = php_needle_to_type(needle, haystack_type, &needle_len, 
needle_char, u_needle_char TSRMLS_CC);

if(target.v == NULL) {
RETURN_FALSE;
@@ -2783,7 +2781,6 @@
zval **needle;
char needle_char[2];
UChar u_needle_char[3];
-   void *found = NULL;
long offset = 0;
char *p, *e;
UChar *u_p, *u_e, *pos;
@@ -2794,7 +2791,7 @@
RETURN_FALSE;
}

-   target = php_needle_to_type(needle, haystack_type, &needle_len, 
needle_char, u_needle_char);
+   target = php_needle_to_type(needle, haystack_type, &needle_len, 
needle_char, u_needle_char TSRMLS_CC);

if(target.v == NULL) {
RETURN_FALSE;
@@ -2950,7 +2947,7 @@
found = zend_memrchr(haystack.s, *Z_STRVAL_PP(needle), 
haystack_len);
}
} else {
-   long needleval = php_needle_char(*needle);
+   long needleval = php_needle_char(*needle TSRMLS_CC);
if(needleval == -1) {
RETURN_FALSE;
}

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

Re: [PHP-CVS] svn: /php/php-src/trunk/ext/standard/ string.c tests/strings/str_replace.phpt tests/strings/stripos.phpt tests/strings/stripos_variation1.phpt tests/strings/stripos_variation10.phpt t

2009-08-15 Thread Hannes Magnusson
On Sat, Aug 15, 2009 at 07:43, Stanislav Malyshev wrote:
> stas                                     Sat, 15 Aug 2009 05:43:18 +
>
> Revision: http://svn.php.net/viewvc?view=revision&revision=287313
>
> Log:
> cleanup string parameter parsing, fix some tests
>
> Changed paths:
>    U   php/php-src/trunk/ext/standard/string.c

+static long php_needle_char(zval *needle)
 {
[...]
+   default: {
+   php_error_docref(NULL TSRMLS_CC, E_WARNING, "needle is 
not a
string or an integer");

you are missing TSRMLS_DC

-Hannes

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