]> granicus.if.org Git - php/commitdiff
check the encoding of argument for mb_ereg, mb_ereg_replace, mb_ereg_search_init
authorMasaki Kagaya <masakielastic@gmail.com>
Sun, 1 Mar 2015 12:49:10 +0000 (21:49 +0900)
committerAnatol Belski <ab@php.net>
Sun, 17 Jul 2016 12:19:45 +0000 (14:19 +0200)
ext/mbstring/php_mbregex.c

index b427980430431cf5cfa3c3b476dd0a3f62db0cde..a012ee2f355a487aed20e7772460f161c23eb5e5 100644 (file)
@@ -703,6 +703,16 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
                RETURN_FALSE;
        }
 
+       if (!php_mb_check_encoding(
+       string,
+       string_len,
+       _php_mb_regex_mbctype2name(MBREX(current_mbctype))
+       )) {
+               zval_dtor(array);
+               array_init(array);
+               RETURN_FALSE;
+       }
+
        options = MBREX(regex_default_options);
        if (icase) {
                options |= ONIG_OPTION_IGNORECASE;
@@ -848,6 +858,14 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
                        }
                }
 
+               if (!php_mb_check_encoding(
+               string,
+               string_len,
+               _php_mb_regex_mbctype2name(MBREX(current_mbctype))
+               )) {
+                       RETURN_NULL();
+               }
+
                if (option_str != NULL) {
                        _php_mb_regex_init_options(option_str, option_str_len, &options, &syntax, &eval);
                } else {
@@ -1361,14 +1379,22 @@ PHP_FUNCTION(mb_ereg_search_init)
 
        ZVAL_DUP(&MBREX(search_str), arg_str);
 
-       MBREX(search_pos) = 0;
+       if (php_mb_check_encoding(
+       Z_STRVAL_P(arg_str),
+       Z_STRLEN_P(arg_str),
+       _php_mb_regex_mbctype2name(MBREX(current_mbctype))
+       )) {
+               MBREX(search_pos) = 0;
+               RETVAL_TRUE;
+       } else {
+               MBREX(search_pos) = Z_STRLEN_P(arg_str);
+               RETVAL_FALSE;
+       }
 
        if (MBREX(search_regs) != NULL) {
                onig_region_free(MBREX(search_regs), 1);
                MBREX(search_regs) = NULL;
        }
-
-       RETURN_TRUE;
 }
 /* }}} */