mirror of
https://github.com/php/php-src.git
synced 2025-08-20 09:24:05 +02:00
-fix mb_detect_order
-php_mbstring_parse_encoding_list/array return 0 on any illegal input
This commit is contained in:
parent
ce00085cdd
commit
df82b2ec75
1 changed files with 42 additions and 10 deletions
|
@ -220,10 +220,14 @@ ZEND_GET_MODULE(mbstring)
|
||||||
#endif
|
#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
|
static int
|
||||||
php_mbstring_parse_encoding_list(const char *value, int value_length, int **return_list, int *return_size, int persistent)
|
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;
|
char *p, *p1, *p2, *endp, *tmpstr;
|
||||||
enum mbfl_no_encoding no_encoding;
|
enum mbfl_no_encoding no_encoding;
|
||||||
|
|
||||||
|
@ -283,6 +287,8 @@ php_mbstring_parse_encoding_list(const char *value, int value_length, int **retu
|
||||||
} else if (no_encoding != mbfl_no_encoding_invalid) {
|
} else if (no_encoding != mbfl_no_encoding_invalid) {
|
||||||
*entry++ = no_encoding;
|
*entry++ = no_encoding;
|
||||||
n++;
|
n++;
|
||||||
|
} else {
|
||||||
|
ret = 0;
|
||||||
}
|
}
|
||||||
p1 = p2 + 1;
|
p1 = p2 + 1;
|
||||||
} while (n < size && p2 != NULL);
|
} while (n < size && p2 != NULL);
|
||||||
|
@ -301,15 +307,19 @@ php_mbstring_parse_encoding_list(const char *value, int value_length, int **retu
|
||||||
return 0;
|
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
|
static int
|
||||||
php_mbstring_parse_encoding_array(zval *array, int **return_list, int *return_size, int persistent)
|
php_mbstring_parse_encoding_array(zval *array, int **return_list, int *return_size, int persistent)
|
||||||
{
|
{
|
||||||
zval **hash_entry;
|
zval **hash_entry;
|
||||||
HashTable *target_hash;
|
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;
|
enum mbfl_no_encoding no_encoding;
|
||||||
|
|
||||||
list = NULL;
|
list = NULL;
|
||||||
|
@ -343,6 +353,8 @@ php_mbstring_parse_encoding_array(zval *array, int **return_list, int *return_si
|
||||||
} else if (no_encoding != mbfl_no_encoding_invalid) {
|
} else if (no_encoding != mbfl_no_encoding_invalid) {
|
||||||
*entry++ = no_encoding;
|
*entry++ = no_encoding;
|
||||||
n++;
|
n++;
|
||||||
|
} else {
|
||||||
|
ret = 0;;
|
||||||
}
|
}
|
||||||
zend_hash_move_forward(target_hash);
|
zend_hash_move_forward(target_hash);
|
||||||
i--;
|
i--;
|
||||||
|
@ -361,7 +373,7 @@ php_mbstring_parse_encoding_array(zval *array, int **return_list, int *return_si
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAVE_MBREGEX
|
#if HAVE_MBREGEX
|
||||||
|
@ -767,7 +779,7 @@ PHP_FUNCTION(mb_internal_encoding)
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
/* {{{ proto string mb_http_input([string type])
|
/* {{{ proto false|string mb_http_input([string type])
|
||||||
Returns the input encoding */
|
Returns the input encoding */
|
||||||
PHP_FUNCTION(mb_http_input)
|
PHP_FUNCTION(mb_http_input)
|
||||||
{
|
{
|
||||||
|
@ -867,7 +879,7 @@ PHP_FUNCTION(mb_http_output)
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
/* {{{ 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 */
|
Sets the current detect_order or Return the current detect_order as a array */
|
||||||
PHP_FUNCTION(mb_detect_order)
|
PHP_FUNCTION(mb_detect_order)
|
||||||
{
|
{
|
||||||
|
@ -894,11 +906,21 @@ PHP_FUNCTION(mb_detect_order)
|
||||||
size = 0;
|
size = 0;
|
||||||
switch (Z_TYPE_PP(arg1)) {
|
switch (Z_TYPE_PP(arg1)) {
|
||||||
case IS_ARRAY:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
convert_to_string_ex(arg1);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
if (list == NULL) {
|
if (list == NULL) {
|
||||||
|
@ -2249,11 +2271,21 @@ PHP_FUNCTION(mb_detect_encoding)
|
||||||
if (ZEND_NUM_ARGS() >= 2) {
|
if (ZEND_NUM_ARGS() >= 2) {
|
||||||
switch (Z_TYPE_PP(arg_list)) {
|
switch (Z_TYPE_PP(arg_list)) {
|
||||||
case IS_ARRAY:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
convert_to_string_ex(arg_list);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
if (size <= 0) {
|
if (size <= 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue