]> granicus.if.org Git - php/commitdiff
Fix mbstring fallback when --disable-mbregex used
authorAnatol Belski <ab@php.net>
Mon, 11 Jun 2018 15:43:29 +0000 (17:43 +0200)
committerAnatol Belski <ab@php.net>
Mon, 11 Jun 2018 15:44:34 +0000 (17:44 +0200)
ext/mbstring/mbstring.c

index b17b8f8f8e0737a1ad6f171cd01d73346cc7caec..2c2a4824cc36d3cdecc3ca01df5d351df6bbd1eb 100644 (file)
@@ -1045,13 +1045,15 @@ static void _php_mb_free_regex(void *opaque)
 /* {{{ _php_mb_compile_regex */
 static void *_php_mb_compile_regex(const char *pattern)
 {
-       pcre *retval;
-       const char *err_str;
-       int err_offset;
+       pcre2_code *retval;
+       PCRE2_SIZE err_offset;
+       int errnum;
 
-       if (!(retval = pcre_compile(pattern,
-                       PCRE_CASELESS, &err_str, &err_offset, NULL))) {
-               php_error_docref(NULL, E_WARNING, "%s (offset=%d): %s", pattern, err_offset, err_str);
+       if (!(retval = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED,
+                       PCRE2_CASELESS, &errnum, &err_offset, php_pcre_cctx()))) {
+               PCRE2_UCHAR err_str[256];
+               pcre2_get_error_message(errnum, err_str, sizeof(err_str));
+               php_error_docref(NULL, E_WARNING, "%s (offset=%zu): %s", pattern, err_offset, err_str);
        }
        return retval;
 }
@@ -1060,15 +1062,25 @@ static void *_php_mb_compile_regex(const char *pattern)
 /* {{{ _php_mb_match_regex */
 static int _php_mb_match_regex(void *opaque, const char *str, size_t str_len)
 {
-       return pcre_exec((pcre *)opaque, NULL, str, (int)str_len, 0,
-                       0, NULL, 0) >= 0;
+       int res;
+
+       pcre2_match_data *match_data = php_pcre_create_match_data(0, opaque);
+       if (NULL == match_data) {
+               pcre2_code_free(opaque);
+               php_error_docref(NULL, E_WARNING, "Cannot allocate match data");
+               return FAILURE;
+       }
+       res = pcre2_match(opaque, (PCRE2_SPTR)str, str_len, 0, 0, match_data, php_pcre_mctx());
+       php_pcre_free_match_data(match_data);
+
+       return res;
 }
 /* }}} */
 
 /* {{{ _php_mb_free_regex */
 static void _php_mb_free_regex(void *opaque)
 {
-       pcre_free(opaque);
+       pcre2_code_free(opaque);
 }
 /* }}} */
 #endif