@@ -445,13 +445,18 @@ static php_mb_regex_t *php_mbregex_compile_pattern(const char *pattern, size_t p
445445 OnigErrorInfo err_info ;
446446 OnigUChar err_str [ONIG_MAX_ERROR_MESSAGE_LEN ];
447447
448+ if (!php_mb_check_encoding (pattern , patlen , _php_mb_regex_mbctype2name (enc ))) {
449+ php_error_docref (NULL , E_WARNING ,
450+ "Pattern is not valid under %s encoding" , _php_mb_regex_mbctype2name (enc ));
451+ return NULL ;
452+ }
453+
448454 rc = zend_hash_str_find_ptr (& MBREX (ht_rc ), (char * )pattern , patlen );
449455 if (!rc || onig_get_options (rc ) != options || onig_get_encoding (rc ) != enc || onig_get_syntax (rc ) != syntax ) {
450456 if ((err_code = onig_new (& retval , (OnigUChar * )pattern , (OnigUChar * )(pattern + patlen ), options , enc , syntax , & err_info )) != ONIG_NORMAL ) {
451457 onig_error_code_to_str (err_str , err_code , & err_info );
452458 php_error_docref (NULL , E_WARNING , "mbregex compile err: %s" , err_str );
453- retval = NULL ;
454- goto out ;
459+ return NULL ;
455460 }
456461 if (rc == MBREX (search_re )) {
457462 /* reuse the new rc? see bug #72399 */
@@ -461,7 +466,6 @@ static php_mb_regex_t *php_mbregex_compile_pattern(const char *pattern, size_t p
461466 } else {
462467 retval = rc ;
463468 }
464- out :
465469 return retval ;
466470}
467471/* }}} */
@@ -1249,6 +1253,11 @@ PHP_FUNCTION(mb_split)
12491253 count -- ;
12501254 }
12511255
1256+ if (!php_mb_check_encoding (string , string_len ,
1257+ _php_mb_regex_mbctype2name (MBREX (current_mbctype )))) {
1258+ RETURN_FALSE ;
1259+ }
1260+
12521261 /* create regex pattern buffer */
12531262 if ((re = php_mbregex_compile_pattern (arg_pattern , arg_pattern_len , MBREX (regex_default_options ), MBREX (current_mbctype ), MBREX (regex_default_syntax ))) == NULL ) {
12541263 RETURN_FALSE ;
@@ -1338,6 +1347,11 @@ PHP_FUNCTION(mb_ereg_match)
13381347 }
13391348 }
13401349
1350+ if (!php_mb_check_encoding (string , string_len ,
1351+ _php_mb_regex_mbctype2name (MBREX (current_mbctype )))) {
1352+ RETURN_FALSE ;
1353+ }
1354+
13411355 if ((re = php_mbregex_compile_pattern (arg_pattern , arg_pattern_len , option , MBREX (current_mbctype ), syntax )) == NULL ) {
13421356 RETURN_FALSE ;
13431357 }
0 commit comments