com php-src: fixed strip_tags() and hebrev() to work with big strings: ext/standard/string.c
| From: | Anatol Belski | Date: | Thu, 28 Aug 2014 17:35:37 +0000 |
| Subject: | com php-src: fixed strip_tags() and hebrev() to work with big strings: ext/standard/string.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-81271@lists.php.net to get a copy of this message | ||
Commit: 8e05b9104bef1251f44a66cd038e6c4bce546e1e
Author: Anatol Belski <ab@php.net> Thu, 28 Aug 2014 19:35:37 +0200
Parents: d6faac2cb2a9f9bec9e31467fe3ac15263434099
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=8e05b9104bef1251f44a66cd038e6c4bce546e1e
Log:
fixed strip_tags() and hebrev() to work with big strings
Changed paths:
M ext/standard/string.c
Diff:
diff --git a/ext/standard/string.c b/ext/standard/string.c
index c0423fc..a37b858b 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -3878,9 +3878,9 @@ static void php_hebrev(INTERNAL_FUNCTION_PARAMETERS, int convert_newlines)
{
char *str;
char *heb_str, *tmp, *target;
- int block_start, block_end, block_type, block_length, i;
+ size_t block_start, block_end, block_type, block_length, i;
zend_long max_chars=0;
- int begin, end, char_count, orig_begin;
+ size_t begin, end, char_count, orig_begin;
size_t str_len;
zend_string *broken_str;
@@ -3915,8 +3915,8 @@ static void php_hebrev(INTERNAL_FUNCTION_PARAMETERS, int convert_newlines)
block_end++;
block_length++;
}
- for (i = block_start; i<= block_end; i++) {
- *target = str[i];
+ for (i = block_start+1; i<= block_end+1; i++) {
+ *target = str[i-1];
switch (*target) {
case '(':
*target = ')';
@@ -3964,8 +3964,8 @@ static void php_hebrev(INTERNAL_FUNCTION_PARAMETERS, int convert_newlines)
tmp--;
block_end--;
}
- for (i = block_end; i >= block_start; i--) {
- *target = str[i];
+ for (i = block_end+1; i >= block_start+1; i--) {
+ *target = str[i-1];
target--;
}
block_type = _HEB_BLOCK_TYPE_HEB;
@@ -3980,7 +3980,7 @@ static void php_hebrev(INTERNAL_FUNCTION_PARAMETERS, int convert_newlines)
while (1) {
char_count=0;
- while ((!max_chars || char_count < max_chars) && begin > 0) {
+ while ((!max_chars || max_chars > 0 && char_count < max_chars) && begin
> 0) {
char_count++;
begin--;
if (begin <= 0 || _isnewline(heb_str[begin])) {
@@ -3991,8 +3991,8 @@ static void php_hebrev(INTERNAL_FUNCTION_PARAMETERS, int convert_newlines)
break;
}
}
- if (char_count == max_chars) { /* try to avoid breaking words */
- int new_char_count=char_count, new_begin=begin;
+ if (max_chars >= 0 && char_count == max_chars) { /* try to avoid breaking words */
+ size_t new_char_count=char_count, new_begin=begin;
while (new_char_count > 0) {
if (_isblank(heb_str[new_begin]) || _isnewline(heb_str[new_begin])) {
@@ -4146,7 +4146,7 @@ PHP_FUNCTION(strip_tags)
zend_string *str;
zval *allow=NULL;
char *allowed_tags=NULL;
- int allowed_tags_len=0;
+ size_t allowed_tags_len=0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|z", &str, &allow) ==
FAILURE) {
return;
@@ -4417,8 +4417,9 @@ PHPAPI size_t php_strip_tags(char *rbuf, size_t len, int *stateptr, char
*allow,
PHPAPI size_t php_strip_tags_ex(char *rbuf, size_t len, int *stateptr, char *allow, size_t
allow_len, zend_bool allow_tag_spaces)
{
char *tbuf, *buf, *p, *tp, *rp, c, lc;
- int br, i=0, depth=0, in_q = 0;
- int state = 0, pos;
+ int br, depth=0, in_q = 0;
+ int state = 0;
+ size_t pos, i = 0;
char *allow_free = NULL;
if (stateptr)
@@ -5122,7 +5123,8 @@ PHP_FUNCTION(sscanf)
{
zval *args = NULL;
char *str, *format;
- size_t str_len, format_len, result, num_args = 0;
+ size_t str_len, format_len;
+ int result, num_args = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss*", &str, &str_len,
&format, &format_len,
&args, &num_args) == FAILURE) {