[PHP-CVS] cvs: php-src(PHP_5_2) /ext/mbstring php_mbregex.c

2008-02-16 Thread Rui Hirokawa
hirokawaSun Feb 17 02:04:12 2008 UTC

  Modified files:  (Branch: PHP_5_2)
/php-src/ext/mbstring   php_mbregex.c 
  Log:
  MF PHP5_3 (fixed #43994)
  
http://cvs.php.net/viewvc.cgi/php-src/ext/mbstring/php_mbregex.c?r1=1.53.2.1.2.6r2=1.53.2.1.2.7diff_format=u
Index: php-src/ext/mbstring/php_mbregex.c
diff -u php-src/ext/mbstring/php_mbregex.c:1.53.2.1.2.6 
php-src/ext/mbstring/php_mbregex.c:1.53.2.1.2.7
--- php-src/ext/mbstring/php_mbregex.c:1.53.2.1.2.6 Mon Dec 31 07:20:07 2007
+++ php-src/ext/mbstring/php_mbregex.c  Sun Feb 17 02:04:12 2008
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: php_mbregex.c,v 1.53.2.1.2.6 2007/12/31 07:20:07 sebastian Exp $ */
+/* $Id: php_mbregex.c,v 1.53.2.1.2.7 2008/02/17 02:04:12 hirokawa Exp $ */
 
 
 #ifdef HAVE_CONFIG_H
@@ -546,6 +546,13 @@
convert_to_string_ex(arg_pattern);
/* don't bother doing an extended regex with just a number */
}
+
+   if (!Z_STRVAL_PP(arg_pattern) || Z_STRLEN_PP(arg_pattern) == 0) {
+   php_error_docref(NULL TSRMLS_CC, E_WARNING, empty pattern);
+   RETVAL_FALSE;
+   goto out;
+   }
+
re = php_mbregex_compile_pattern(Z_STRVAL_PP(arg_pattern), 
Z_STRLEN_PP(arg_pattern), options, MBSTRG(current_mbctype), 
MBSTRG(regex_default_syntax) TSRMLS_CC);
if (re == NULL) {
RETVAL_FALSE;

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



[PHP-CVS] cvs: php-src(PHP_5_2) /ext/mbstring php_mbregex.c

2007-01-11 Thread Antony Dovgal
tony2001Thu Jan 11 22:23:20 2007 UTC

  Modified files:  (Branch: PHP_5_2)
/php-src/ext/mbstring   php_mbregex.c 
  Log:
  MFH
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/mbstring/php_mbregex.c?r1=1.53.2.1.2.3r2=1.53.2.1.2.4diff_format=u
Index: php-src/ext/mbstring/php_mbregex.c
diff -u php-src/ext/mbstring/php_mbregex.c:1.53.2.1.2.3 
php-src/ext/mbstring/php_mbregex.c:1.53.2.1.2.4
--- php-src/ext/mbstring/php_mbregex.c:1.53.2.1.2.3 Mon Jan  1 09:36:02 2007
+++ php-src/ext/mbstring/php_mbregex.c  Thu Jan 11 22:23:20 2007
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: php_mbregex.c,v 1.53.2.1.2.3 2007/01/01 09:36:02 sebastian Exp $ */
+/* $Id: php_mbregex.c,v 1.53.2.1.2.4 2007/01/11 22:23:20 tony2001 Exp $ */
 
 
 #ifdef HAVE_CONFIG_H
@@ -607,7 +607,7 @@
 /* {{{ _php_mb_regex_ereg_replace_exec */
 static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, 
OnigOptionType options)
 {
-   zval *arg_pattern_zval;
+   zval **arg_pattern_zval;
 
char *arg_pattern;
int arg_pattern_len;
@@ -647,7 +647,7 @@
char *option_str = NULL;
int option_str_len = 0;
 
-   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, zss|s,
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, Zss|s,

arg_pattern_zval,

replace, replace_len,

string, string_len,
@@ -662,13 +662,13 @@
syntax = MBSTRG(regex_default_syntax);
}
}
-   if (Z_TYPE_P(arg_pattern_zval) == IS_STRING) {
-   arg_pattern = Z_STRVAL_P(arg_pattern_zval);
-   arg_pattern_len = Z_STRLEN_P(arg_pattern_zval);
+   if (Z_TYPE_PP(arg_pattern_zval) == IS_STRING) {
+   arg_pattern = Z_STRVAL_PP(arg_pattern_zval);
+   arg_pattern_len = Z_STRLEN_PP(arg_pattern_zval);
} else {
/* FIXME: this code is not multibyte aware! */
-   convert_to_long_ex(arg_pattern_zval);
-   pat_buf[0] = (char)Z_LVAL_P(arg_pattern_zval);  
+   convert_to_long_ex(arg_pattern_zval);
+   pat_buf[0] = (char)Z_LVAL_PP(arg_pattern_zval); 
pat_buf[1] = '\0';
 
arg_pattern = pat_buf;

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



[PHP-CVS] cvs: php-src(PHP_5_2) /ext/mbstring php_mbregex.c /ext/mbstring/tests mb_ereg1.phpt

2006-10-11 Thread Antony Dovgal
tony2001Wed Oct 11 11:09:42 2006 UTC

  Added files: (Branch: PHP_5_2)
/php-src/ext/mbstring/tests mb_ereg1.phpt 

  Modified files:  
/php-src/ext/mbstring   php_mbregex.c 
  Log:
  MFH: fix segfault/leak, add test
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/mbstring/php_mbregex.c?r1=1.53.2.1r2=1.53.2.1.2.1diff_format=u
Index: php-src/ext/mbstring/php_mbregex.c
diff -u php-src/ext/mbstring/php_mbregex.c:1.53.2.1 
php-src/ext/mbstring/php_mbregex.c:1.53.2.1.2.1
--- php-src/ext/mbstring/php_mbregex.c:1.53.2.1 Sun Jan  1 12:50:08 2006
+++ php-src/ext/mbstring/php_mbregex.c  Wed Oct 11 11:09:42 2006
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: php_mbregex.c,v 1.53.2.1 2006/01/01 12:50:08 sniper Exp $ */
+/* $Id: php_mbregex.c,v 1.53.2.1.2.1 2006/10/11 11:09:42 tony2001 Exp $ */
 
 
 #ifdef HAVE_CONFIG_H
@@ -518,7 +518,7 @@
 static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
 {
zval tmp;
-   zval *arg_pattern, *array;
+   zval **arg_pattern, *array;
char *string;
int string_len;
php_mb_regex_t *re;
@@ -529,7 +529,7 @@
 
array = NULL;
 
-   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, zs|z, 
arg_pattern, string, string_len, array) == FAILURE) {
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, Zs|z, 
arg_pattern, string, string_len, array) == FAILURE) {
RETURN_FALSE;
}
 
@@ -539,18 +539,15 @@
}
 
/* compile the regular expression from the supplied regex */
-   if (Z_TYPE_P(arg_pattern) != IS_STRING) {
+   if (Z_TYPE_PP(arg_pattern) != IS_STRING) {
/* we convert numbers to integers and treat them as a string */
-   tmp = *arg_pattern;
-   zval_copy_ctor(tmp);
-   if (Z_TYPE_P(tmp) == IS_DOUBLE) {
-   convert_to_long(tmp);  /* get rid of decimal places */
+   if (Z_TYPE_PP(arg_pattern) == IS_DOUBLE) {
+   convert_to_long_ex(arg_pattern);/* get rid of 
decimal places */
}
-   convert_to_string(tmp);
-   arg_pattern = tmp;
+   convert_to_string_ex(arg_pattern);
/* don't bother doing an extended regex with just a number */
}
-   re = php_mbregex_compile_pattern(Z_STRVAL_P(arg_pattern), 
Z_STRLEN_P(arg_pattern), options, MBSTRG(current_mbctype), 
MBSTRG(regex_default_syntax) TSRMLS_CC);
+   re = php_mbregex_compile_pattern(Z_STRVAL_PP(arg_pattern), 
Z_STRLEN_PP(arg_pattern), options, MBSTRG(current_mbctype), 
MBSTRG(regex_default_syntax) TSRMLS_CC);
if (re == NULL) {
RETVAL_FALSE;
goto out;
@@ -590,9 +587,6 @@
if (regs != NULL) {
onig_region_free(regs, 1);
}
-   if (arg_pattern == tmp) {
-   zval_dtor(tmp);
-   }
 }
 /* }}} */
 

http://cvs.php.net/viewvc.cgi/php-src/ext/mbstring/tests/mb_ereg1.phpt?view=markuprev=1.1
Index: php-src/ext/mbstring/tests/mb_ereg1.phpt
+++ php-src/ext/mbstring/tests/mb_ereg1.phpt
--TEST--
mb_ereg() and invalid arguments
--SKIPIF--
?php if (!function_exists(mb_ereg)) print skip; ?
--FILE--
?php

$a = array(
array(1,2,3),
array(, , ),
array(array(), 1, ),
array(1, array(), ),
array(1, , array()),
);

foreach ($a as $args) {
var_dump(mb_ereg($args[0], $args[1], $args[2]));
var_dump($args);
}

echo Done\n;
?
--EXPECTF-- 
bool(false)
array(3) {
  [0]=
  int(1)
  [1]=
  int(2)
  [2]=
  int(3)
}
int(1)
array(3) {
  [0]=
  string(0) 
  [1]=
  string(0) 
  [2]=
  array(1) {
[0]=
bool(false)
  }
}

Notice: Array to string conversion in %s on line %d
bool(false)
array(3) {
  [0]=
  array(0) {
  }
  [1]=
  int(1)
  [2]=
  string(0) 
}

Warning: mb_ereg() expects parameter 2 to be string, array given in %s on line 
%d
bool(false)
array(3) {
  [0]=
  int(1)
  [1]=
  array(0) {
  }
  [2]=
  string(0) 
}
bool(false)
array(3) {
  [0]=
  int(1)
  [1]=
  string(0) 
  [2]=
  array(0) {
  }
}
Done

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



[PHP-CVS] cvs: php-src(PHP_5_2) /ext/mbstring php_mbregex.c /ext/mbstring/tests mb_ereg2.phpt

2006-10-11 Thread Antony Dovgal
tony2001Wed Oct 11 11:53:02 2006 UTC

  Added files: (Branch: PHP_5_2)
/php-src/ext/mbstring/tests mb_ereg2.phpt 

  Modified files:  
/php-src/ext/mbstring   php_mbregex.c 
  Log:
  MFH
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/mbstring/php_mbregex.c?r1=1.53.2.1.2.1r2=1.53.2.1.2.2diff_format=u
Index: php-src/ext/mbstring/php_mbregex.c
diff -u php-src/ext/mbstring/php_mbregex.c:1.53.2.1.2.1 
php-src/ext/mbstring/php_mbregex.c:1.53.2.1.2.2
--- php-src/ext/mbstring/php_mbregex.c:1.53.2.1.2.1 Wed Oct 11 11:09:42 2006
+++ php-src/ext/mbstring/php_mbregex.c  Wed Oct 11 11:53:02 2006
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: php_mbregex.c,v 1.53.2.1.2.1 2006/10/11 11:09:42 tony2001 Exp $ */
+/* $Id: php_mbregex.c,v 1.53.2.1.2.2 2006/10/11 11:53:02 tony2001 Exp $ */
 
 
 #ifdef HAVE_CONFIG_H
@@ -517,7 +517,6 @@
 /* {{{ _php_mb_regex_ereg_exec */
 static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
 {
-   zval tmp;
zval **arg_pattern, *array;
char *string;
int string_len;
@@ -564,19 +563,18 @@
match_len = 1;
str = string;
if (array != NULL) {
-   zval ret_array;
match_len = regs-end[0] - regs-beg[0];
-   array_init(ret_array);
+   zval_dtor(array);
+   array_init(array);
for (i = 0; i  regs-num_regs; i++) {
beg = regs-beg[i];
end = regs-end[i];
if (beg = 0  beg  end  end = string_len) {
-   add_index_stringl(ret_array, i, (char 
*)str[beg], end - beg, 1);
+   add_index_stringl(array, i, (char *)str[beg], 
end - beg, 1);
} else {
-   add_index_bool(ret_array, i, 0);
+   add_index_bool(array, i, 0);
}
}
-   REPLACE_ZVAL_VALUE(array, ret_array, 0);
}
 
if (match_len == 0) {
@@ -1098,6 +1096,7 @@
WRONG_PARAM_COUNT;
break;
}
+   convert_to_string_ex(arg_str);
if (ZEND_NUM_ARGS()  1) {
/* create regex pattern buffer */
convert_to_string_ex(arg_pattern);

http://cvs.php.net/viewvc.cgi/php-src/ext/mbstring/tests/mb_ereg2.phpt?view=markuprev=1.1
Index: php-src/ext/mbstring/tests/mb_ereg2.phpt
+++ php-src/ext/mbstring/tests/mb_ereg2.phpt
--TEST--
mb_ereg() returning matches
--SKIPIF--
?php if (!function_exists(mb_ereg)) print skip; ?
--FILE--
?php

$a = -1; $b = -1; $c = -1; 
mbereg($a, $b, $c); 
var_dump($a, $b, $c); 

mberegi($a, $b, $c); 
var_dump($a, $b, $c); 

mbereg_search_init($a, $b, $c); 
var_dump($a, $b, $c);

echo Done\n;
?
--EXPECTF-- 
int(-1)
int(-1)
array(1) {
  [0]=
  string(2) -1
}
int(-1)
int(-1)
array(1) {
  [0]=
  string(2) -1
}

Notice: Array to string conversion in %s on line %d
int(-1)
int(-1)
array(1) {
  [0]=
  string(2) -1
}
Done

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