Skip to content

Commit eb3e7f7

Browse files
masakielasticweltling
authored andcommitted
check the encoding of argument for mb_ereg, mb_ereg_replace, mb_ereg_search_init
1 parent ee6ccea commit eb3e7f7

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

ext/mbstring/php_mbregex.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,16 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
703703
RETURN_FALSE;
704704
}
705705

706+
if (!php_mb_check_encoding(
707+
string,
708+
string_len,
709+
_php_mb_regex_mbctype2name(MBREX(current_mbctype))
710+
)) {
711+
zval_dtor(array);
712+
array_init(array);
713+
RETURN_FALSE;
714+
}
715+
706716
options = MBREX(regex_default_options);
707717
if (icase) {
708718
options |= ONIG_OPTION_IGNORECASE;
@@ -848,6 +858,14 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
848858
}
849859
}
850860

861+
if (!php_mb_check_encoding(
862+
string,
863+
string_len,
864+
_php_mb_regex_mbctype2name(MBREX(current_mbctype))
865+
)) {
866+
RETURN_NULL();
867+
}
868+
851869
if (option_str != NULL) {
852870
_php_mb_regex_init_options(option_str, option_str_len, &options, &syntax, &eval);
853871
} else {
@@ -1361,14 +1379,22 @@ PHP_FUNCTION(mb_ereg_search_init)
13611379

13621380
ZVAL_DUP(&MBREX(search_str), arg_str);
13631381

1364-
MBREX(search_pos) = 0;
1382+
if (php_mb_check_encoding(
1383+
Z_STRVAL_P(arg_str),
1384+
Z_STRLEN_P(arg_str),
1385+
_php_mb_regex_mbctype2name(MBREX(current_mbctype))
1386+
)) {
1387+
MBREX(search_pos) = 0;
1388+
RETVAL_TRUE;
1389+
} else {
1390+
MBREX(search_pos) = Z_STRLEN_P(arg_str);
1391+
RETVAL_FALSE;
1392+
}
13651393

13661394
if (MBREX(search_regs) != NULL) {
13671395
onig_region_free(MBREX(search_regs), 1);
13681396
MBREX(search_regs) = NULL;
13691397
}
1370-
1371-
RETURN_TRUE;
13721398
}
13731399
/* }}} */
13741400

0 commit comments

Comments
 (0)