cvs: php4 /ext/mbstring mbstring.c
| From: | Marcus B�rger | Date: | Fri, 12 Apr 2002 14:24:55 +0000 |
| Subject: | cvs: php4 /ext/mbstring mbstring.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-11082@lists.php.net to get a copy of this message | ||
helly Fri Apr 12 10:24:55 2002 EDT
Modified files:
/php4/ext/mbstring mbstring.c
Log:
-fix mb_detect_order
-php_mbstring_parse_encoding_list/array return 0 on any illegal input
Index: php4/ext/mbstring/mbstring.c
diff -u php4/ext/mbstring/mbstring.c:1.59 php4/ext/mbstring/mbstring.c:1.60
--- php4/ext/mbstring/mbstring.c:1.59 Thu Apr 11 18:52:43 2002
+++ php4/ext/mbstring/mbstring.c Fri Apr 12 10:24:54 2002
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: mbstring.c,v 1.59 2002/04/11 22:52:43 helly Exp $ */
+/* $Id: mbstring.c,v 1.60 2002/04/12 14:24:54 helly Exp $ */
/*
* PHP4 Multibyte String module "mbstring" (currently only for Japanese)
@@ -220,10 +220,14 @@
#endif
+/* Return 0 if input contains any illegal encoding, otherwise 1.
+ * Even if any illegal encoding is detected the result may contain a list
+ * of parsed encodings.
+ */
static int
php_mbstring_parse_encoding_list(const char *value, int value_length, int **return_list, int
*return_size, int persistent)
{
- int n, l, size, bauto, *src, *list, *entry;
+ int n, l, size, bauto, *src, *list, *entry, ret = 1;
char *p, *p1, *p2, *endp, *tmpstr;
enum mbfl_no_encoding no_encoding;
@@ -283,6 +287,8 @@
} else if (no_encoding != mbfl_no_encoding_invalid) {
*entry++ = no_encoding;
n++;
+ } else {
+ ret = 0;
}
p1 = p2 + 1;
} while (n < size && p2 != NULL);
@@ -301,15 +307,19 @@
return 0;
}
- return 1;
+ return ret;
}
+/* Return 0 if input contains any illegal encoding, otherwise 1.
+ * Even if any illegal encoding is detected the result may contain a list
+ * of parsed encodings.
+ */
static int
php_mbstring_parse_encoding_array(zval *array, int **return_list, int *return_size, int persistent)
{
zval **hash_entry;
HashTable *target_hash;
- int i, n, l, size, bauto, *list, *entry, *src;
+ int i, n, l, size, bauto, *list, *entry, *src, ret = 1;
enum mbfl_no_encoding no_encoding;
list = NULL;
@@ -343,6 +353,8 @@
} else if (no_encoding != mbfl_no_encoding_invalid) {
*entry++ = no_encoding;
n++;
+ } else {
+ ret = 0;;
}
zend_hash_move_forward(target_hash);
i--;
@@ -361,7 +373,7 @@
return 0;
}
- return 1;
+ return ret;
}
#if HAVE_MBREGEX
@@ -767,7 +779,7 @@
/* }}} */
-/* {{{ proto string mb_http_input([string type])
+/* {{{ proto false|string mb_http_input([string type])
Returns the input encoding */
PHP_FUNCTION(mb_http_input)
{
@@ -867,7 +879,7 @@
/* }}} */
-/* {{{ proto array mb_detect_order([mixed encoding-list])
+/* {{{ proto boolean|array mb_detect_order([mixed encoding-list])
Sets the current detect_order or Return the current detect_order as a array */
PHP_FUNCTION(mb_detect_order)
{
@@ -894,11 +906,21 @@
size = 0;
switch (Z_TYPE_PP(arg1)) {
case IS_ARRAY:
- php_mbstring_parse_encoding_array(*arg1, &list, &size, 0);
+ if (!php_mbstring_parse_encoding_array(*arg1, &list, &size, 0)) {
+ if (list) {
+ efree(list);
+ }
+ RETURN_FALSE;
+ }
break;
default:
convert_to_string_ex(arg1);
- php_mbstring_parse_encoding_list(Z_STRVAL_PP(arg1), Z_STRLEN_PP(arg1), &list, &size, 0);
+ if (!php_mbstring_parse_encoding_list(Z_STRVAL_PP(arg1), Z_STRLEN_PP(arg1), &list,
&size, 0)) {
+ if (list) {
+ efree(list);
+ }
+ RETURN_FALSE;
+ }
break;
}
if (list == NULL) {
@@ -2249,11 +2271,21 @@
if (ZEND_NUM_ARGS() >= 2) {
switch (Z_TYPE_PP(arg_list)) {
case IS_ARRAY:
- php_mbstring_parse_encoding_array(*arg_list, &list, &size, 0);
+ if (!php_mbstring_parse_encoding_array(*arg_list, &list, &size, 0)) {
+ if (list) {
+ efree(list);
+ size = 0;
+ }
+ }
break;
default:
convert_to_string_ex(arg_list);
- php_mbstring_parse_encoding_list(Z_STRVAL_PP(arg_list), Z_STRLEN_PP(arg_list), &list,
&size, 0);
+ if (!php_mbstring_parse_encoding_list(Z_STRVAL_PP(arg_list), Z_STRLEN_PP(arg_list), &list,
&size, 0)) {
+ if (list) {
+ efree(list);
+ size = 0;
+ }
+ }
break;
}
if (size <= 0) {