@@ -448,13 +448,18 @@ static php_mb_regex_t *php_mbregex_compile_pattern(const char *pattern, int patl
448448 OnigErrorInfo err_info ;
449449 OnigUChar err_str [ONIG_MAX_ERROR_MESSAGE_LEN ];
450450
451+ if (!php_mb_check_encoding (pattern , patlen , _php_mb_regex_mbctype2name (enc ))) {
452+ php_error_docref (NULL , E_WARNING ,
453+ "Pattern is not valid under %s encoding" , _php_mb_regex_mbctype2name (enc ));
454+ return NULL ;
455+ }
456+
451457 rc = zend_hash_str_find_ptr (& MBREX (ht_rc ), (char * )pattern , patlen );
452458 if (!rc || onig_get_options (rc ) != options || onig_get_encoding (rc ) != enc || onig_get_syntax (rc ) != syntax ) {
453459 if ((err_code = onig_new (& retval , (OnigUChar * )pattern , (OnigUChar * )(pattern + patlen ), options , enc , syntax , & err_info )) != ONIG_NORMAL ) {
454460 onig_error_code_to_str (err_str , err_code , & err_info );
455461 php_error_docref (NULL , E_WARNING , "mbregex compile err: %s" , err_str );
456- retval = NULL ;
457- goto out ;
462+ return NULL ;
458463 }
459464 if (rc == MBREX (search_re )) {
460465 /* reuse the new rc? see bug #72399 */
@@ -464,7 +469,6 @@ static php_mb_regex_t *php_mbregex_compile_pattern(const char *pattern, int patl
464469 } else {
465470 retval = rc ;
466471 }
467- out :
468472 return retval ;
469473}
470474/* }}} */
@@ -1107,6 +1111,11 @@ PHP_FUNCTION(mb_split)
11071111 count -- ;
11081112 }
11091113
1114+ if (!php_mb_check_encoding (string , string_len ,
1115+ _php_mb_regex_mbctype2name (MBREX (current_mbctype )))) {
1116+ RETURN_FALSE ;
1117+ }
1118+
11101119 /* create regex pattern buffer */
11111120 if ((re = php_mbregex_compile_pattern (arg_pattern , arg_pattern_len , MBREX (regex_default_options ), MBREX (current_mbctype ), MBREX (regex_default_syntax ))) == NULL ) {
11121121 RETURN_FALSE ;
@@ -1196,6 +1205,11 @@ PHP_FUNCTION(mb_ereg_match)
11961205 }
11971206 }
11981207
1208+ if (!php_mb_check_encoding (string , string_len ,
1209+ _php_mb_regex_mbctype2name (MBREX (current_mbctype )))) {
1210+ RETURN_FALSE ;
1211+ }
1212+
11991213 if ((re = php_mbregex_compile_pattern (arg_pattern , arg_pattern_len , option , MBREX (current_mbctype ), syntax )) == NULL ) {
12001214 RETURN_FALSE ;
12011215 }
0 commit comments