diff options
author | George Peter Banyard <girgias@php.net> | 2020-04-02 17:05:43 +0200 |
---|---|---|
committer | George Peter Banyard <girgias@php.net> | 2020-09-09 14:55:07 +0200 |
commit | 04441585292e4c75d57a2679c62766701b94ce81 (patch) | |
tree | 8145e905f29231f26148cc3fa3d63288b0a45a92 /ext/mbstring/php_mbregex.c | |
parent | 8f415d441381f1a074e661cffaf9f806b1d8e001 (diff) | |
download | php-git-04441585292e4c75d57a2679c62766701b94ce81.tar.gz |
Promote some warnings in MBString Regexes
Closes GH-5341
Diffstat (limited to 'ext/mbstring/php_mbregex.c')
-rw-r--r-- | ext/mbstring/php_mbregex.c | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c index b5bd79fbe4..45aac7baf2 100644 --- a/ext/mbstring/php_mbregex.c +++ b/ext/mbstring/php_mbregex.c @@ -591,8 +591,8 @@ static size_t _php_mb_regex_get_option_string(char *str, size_t len, OnigOptionT /* }}} */ /* {{{ _php_mb_regex_init_options */ -static void -_php_mb_regex_init_options(const char *parg, size_t narg, OnigOptionType *option, OnigSyntaxType **syntax, int *eval) +static bool _php_mb_regex_init_options(const char *parg, size_t narg, OnigOptionType *option, + OnigSyntaxType **syntax) { size_t n; char c; @@ -650,15 +650,14 @@ _php_mb_regex_init_options(const char *parg, size_t narg, OnigOptionType *option case 'd': *syntax = ONIG_SYNTAX_POSIX_EXTENDED; break; - case 'e': - if (eval != NULL) *eval = 1; - break; default: - break; + zend_value_error("Option \"%c\" is not supported", c); + return false; } } if (option != NULL) *option|=optm; } + return true; } /* }}} */ @@ -900,6 +899,11 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase) RETURN_THROWS(); } + if (arg_pattern_len == 0) { + zend_argument_value_error(1, "must not be empty"); + RETURN_THROWS(); + } + if (array != NULL) { array = zend_try_array_init(array); if (!array) { @@ -920,12 +924,6 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase) options |= ONIG_OPTION_IGNORECASE; } - if (arg_pattern_len == 0) { - php_error_docref(NULL, E_WARNING, "Empty pattern"); - RETVAL_FALSE; - goto out; - } - re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, options, MBREX(regex_default_syntax)); if (re == NULL) { RETVAL_FALSE; @@ -1007,7 +1005,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp smart_str out_buf = {0}; smart_str eval_buf = {0}; smart_str *pbuf; - int err, eval, n; + int err, n; OnigUChar *pos; OnigUChar *string_lim; char *description = NULL; @@ -1015,7 +1013,6 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp const mbfl_encoding *enc = php_mb_regex_get_mbctype_encoding(); ZEND_ASSERT(enc != NULL); - eval = 0; { char *option_str = NULL; size_t option_str_len = 0; @@ -1043,20 +1040,15 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp } if (option_str != NULL) { - _php_mb_regex_init_options(option_str, option_str_len, &options, &syntax, &eval); + /* Initialize option and in case of failure it means there is a value error */ + if (!_php_mb_regex_init_options(option_str, option_str_len, &options, &syntax)) { + RETURN_THROWS(); + } } else { options |= MBREX(regex_default_options); syntax = MBREX(regex_default_syntax); } } - if (eval) { - if (is_callable) { - php_error_docref(NULL, E_WARNING, "Option 'e' cannot be used with replacement callback"); - } else { - php_error_docref(NULL, E_WARNING, "The 'e' option is no longer supported, use mb_ereg_replace_callback instead"); - } - RETURN_FALSE; - } /* create regex pattern buffer */ re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, options, syntax); @@ -1122,7 +1114,9 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp zval_ptr_dtor(&retval); } else { if (!EG(exception)) { - php_error_docref(NULL, E_WARNING, "Unable to call custom replacement function"); + zend_throw_error(NULL, "Unable to call custom replacement function"); + zval_ptr_dtor(&subpats); + RETURN_THROWS(); } } zval_ptr_dtor(&subpats); @@ -1251,6 +1245,7 @@ PHP_FUNCTION(mb_split) onig_region_free(regs, 1); /* see if we encountered an error */ + // ToDo investigate if this can actually/should happen ... if (err <= -2) { OnigUChar err_str[ONIG_MAX_ERROR_MESSAGE_LEN]; onig_error_code_to_str(err_str, err); @@ -1295,7 +1290,9 @@ PHP_FUNCTION(mb_ereg_match) } if (option_str != NULL) { - _php_mb_regex_init_options(option_str, option_str_len, &option, &syntax, NULL); + if(!_php_mb_regex_init_options(option_str, option_str_len, &option, &syntax)) { + RETURN_THROWS(); + } } else { option |= MBREX(regex_default_options); syntax = MBREX(regex_default_syntax); @@ -1348,7 +1345,7 @@ static void _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mod } if (arg_options) { - _php_mb_regex_init_options(arg_options, arg_options_len, &option, &syntax, NULL); + _php_mb_regex_init_options(arg_options, arg_options_len, &option, &syntax); } else { option |= MBREX(regex_default_options); syntax = MBREX(regex_default_syntax); @@ -1375,13 +1372,13 @@ static void _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mod } if (MBREX(search_re) == NULL) { - php_error_docref(NULL, E_WARNING, "No regex given"); - RETURN_FALSE; + zend_throw_error(NULL, "No pattern was provided"); + RETURN_THROWS(); } if (str == NULL) { - php_error_docref(NULL, E_WARNING, "No string given"); - RETURN_FALSE; + zend_throw_error(NULL, "No string was provided"); + RETURN_THROWS(); } MBREX(search_regs) = onig_region_new(); @@ -1480,13 +1477,13 @@ PHP_FUNCTION(mb_ereg_search_init) } if (arg_pattern && arg_pattern_len == 0) { - php_error_docref(NULL, E_WARNING, "Empty pattern"); - RETURN_FALSE; + zend_argument_value_error(2, "must not be empty"); + RETURN_THROWS(); } if (arg_options) { option = 0; - _php_mb_regex_init_options(arg_options, arg_options_len, &option, &syntax, NULL); + _php_mb_regex_init_options(arg_options, arg_options_len, &option, &syntax); } else { option = MBREX(regex_default_options); syntax = MBREX(regex_default_syntax); @@ -1557,6 +1554,7 @@ PHP_FUNCTION(mb_ereg_search_getregs) onig_foreach_name(MBREX(search_re), mb_regex_groups_iter, &args); } } else { + // TODO This seems to be some logical error, promote to Error RETVAL_FALSE; } } @@ -1588,12 +1586,12 @@ PHP_FUNCTION(mb_ereg_search_setpos) } if (position < 0 || (!Z_ISUNDEF(MBREX(search_str)) && Z_TYPE(MBREX(search_str)) == IS_STRING && (size_t)position > Z_STRLEN(MBREX(search_str)))) { - php_error_docref(NULL, E_WARNING, "Position is out of range"); - MBREX(search_pos) = 0; - RETURN_FALSE; + zend_argument_value_error(1, "is out of range"); + RETURN_THROWS(); } MBREX(search_pos) = position; + // TODO Return void RETURN_TRUE; } /* }}} */ @@ -1628,7 +1626,9 @@ PHP_FUNCTION(mb_regex_set_options) if (string != NULL) { opt = 0; syntax = NULL; - _php_mb_regex_init_options(string, string_len, &opt, &syntax, NULL); + if(!_php_mb_regex_init_options(string, string_len, &opt, &syntax)) { + RETURN_THROWS(); + } _php_mb_regex_set_options(opt, syntax, &prev_opt, &prev_syntax); opt = prev_opt; syntax = prev_syntax; |