Skip to content

Commit a34ba6f

Browse files
committed
Fix mbstring fallback when --disable-mbregex used
1 parent dc99a13 commit a34ba6f

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

ext/mbstring/mbstring.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,13 +1045,15 @@ static void _php_mb_free_regex(void *opaque)
10451045
/* {{{ _php_mb_compile_regex */
10461046
static void *_php_mb_compile_regex(const char *pattern)
10471047
{
1048-
pcre *retval;
1049-
const char *err_str;
1050-
int err_offset;
1048+
pcre2_code *retval;
1049+
PCRE2_SIZE err_offset;
1050+
int errnum;
10511051

1052-
if (!(retval = pcre_compile(pattern,
1053-
PCRE_CASELESS, &err_str, &err_offset, NULL))) {
1054-
php_error_docref(NULL, E_WARNING, "%s (offset=%d): %s", pattern, err_offset, err_str);
1052+
if (!(retval = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED,
1053+
PCRE2_CASELESS, &errnum, &err_offset, php_pcre_cctx()))) {
1054+
PCRE2_UCHAR err_str[256];
1055+
pcre2_get_error_message(errnum, err_str, sizeof(err_str));
1056+
php_error_docref(NULL, E_WARNING, "%s (offset=%zu): %s", pattern, err_offset, err_str);
10551057
}
10561058
return retval;
10571059
}
@@ -1060,15 +1062,25 @@ static void *_php_mb_compile_regex(const char *pattern)
10601062
/* {{{ _php_mb_match_regex */
10611063
static int _php_mb_match_regex(void *opaque, const char *str, size_t str_len)
10621064
{
1063-
return pcre_exec((pcre *)opaque, NULL, str, (int)str_len, 0,
1064-
0, NULL, 0) >= 0;
1065+
int res;
1066+
1067+
pcre2_match_data *match_data = php_pcre_create_match_data(0, opaque);
1068+
if (NULL == match_data) {
1069+
pcre2_code_free(opaque);
1070+
php_error_docref(NULL, E_WARNING, "Cannot allocate match data");
1071+
return FAILURE;
1072+
}
1073+
res = pcre2_match(opaque, (PCRE2_SPTR)str, str_len, 0, 0, match_data, php_pcre_mctx());
1074+
php_pcre_free_match_data(match_data);
1075+
1076+
return res;
10651077
}
10661078
/* }}} */
10671079

10681080
/* {{{ _php_mb_free_regex */
10691081
static void _php_mb_free_regex(void *opaque)
10701082
{
1071-
pcre_free(opaque);
1083+
pcre2_code_free(opaque);
10721084
}
10731085
/* }}} */
10741086
#endif

0 commit comments

Comments
 (0)