From 06ed6b89780a5eada4966f4a0512d58cda2936c9 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 1 Feb 2019 15:18:28 +0100 Subject: [PATCH] Make mb_ereg_replace() pattern argument a string --- UPGRADING | 3 + ext/mbstring/php_mbregex.c | 30 ++-------- ext/mbstring/tests/bug72994.phpt | 21 ------- .../tests/mb_ereg_replace_variation1.phpt | 58 +++---------------- 4 files changed, 16 insertions(+), 96 deletions(-) delete mode 100644 ext/mbstring/tests/bug72994.phpt diff --git a/UPGRADING b/UPGRADING index 99d136fbe7d..7d30e6ed174 100644 --- a/UPGRADING +++ b/UPGRADING @@ -94,6 +94,9 @@ PHP 8.0 UPGRADE NOTES . The 'e' modifier for mb_ereg_replace() has been removed. mb_ereg_replace_callback() should be used instead. + . A non-string pattern argument to mb_ereg_replace() will now be interpreted + as a string instead of an ASCII codepoint. The previous behavior may be + restored with an explicit call to chr(). - SPL: . SplFileObject::fgetss() has been removed. diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c index 96c783d589f..3307cfd9cf2 100644 --- a/ext/mbstring/php_mbregex.c +++ b/ext/mbstring/php_mbregex.c @@ -967,8 +967,6 @@ PHP_FUNCTION(mb_eregi) /* {{{ _php_mb_regex_ereg_replace_exec */ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOptionType options, int is_callable) { - zval *arg_pattern_zval; - char *arg_pattern; size_t arg_pattern_len; @@ -991,7 +989,6 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp OnigUChar *pos; OnigUChar *string_lim; char *description = NULL; - char pat_buf[6]; const mbfl_encoding *enc; @@ -1010,16 +1007,16 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp size_t option_str_len = 0; if (!is_callable) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zss|s", - &arg_pattern_zval, + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss|s", + &arg_pattern, &arg_pattern_len, &replace, &replace_len, &string, &string_len, &option_str, &option_str_len) == FAILURE) { RETURN_FALSE; } } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zfs|s", - &arg_pattern_zval, + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sfs|s", + &arg_pattern, &arg_pattern_len, &arg_replace_fci, &arg_replace_fci_cache, &string, &string_len, &option_str, &option_str_len) == FAILURE) { @@ -1046,26 +1043,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp php_error_docref(NULL, E_WARNING, "The 'e' option is no longer supported, use mb_ereg_replace_callback instead"); RETURN_FALSE; } - if (Z_TYPE_P(arg_pattern_zval) == IS_STRING) { - arg_pattern = Z_STRVAL_P(arg_pattern_zval); - arg_pattern_len = Z_STRLEN_P(arg_pattern_zval); - } else { - php_error_docref(NULL, E_DEPRECATED, - "Non-string patterns will be interpreted as strings in the future. " - "Use an explicit chr() call to preserve the current behavior"); - /* FIXME: this code is not multibyte aware! */ - convert_to_long_ex(arg_pattern_zval); - pat_buf[0] = (char)Z_LVAL_P(arg_pattern_zval); - pat_buf[1] = '\0'; - pat_buf[2] = '\0'; - pat_buf[3] = '\0'; - pat_buf[4] = '\0'; - pat_buf[5] = '\0'; - - arg_pattern = pat_buf; - arg_pattern_len = 1; - } /* create regex pattern buffer */ re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, options, MBREX(current_mbctype), syntax); if (re == NULL) { diff --git a/ext/mbstring/tests/bug72994.phpt b/ext/mbstring/tests/bug72994.phpt deleted file mode 100644 index 5cf5b0ecb06..00000000000 --- a/ext/mbstring/tests/bug72994.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Bug #72994 (mbc_to_code() out of bounds read) ---SKIPIF-- - ---FILE-- - -===DONE=== ---EXPECTF-- -Notice: Undefined variable: var in %s on line %d - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d - -Warning: mb_ereg_replace(): mbregex compile err: invalid code point value in %sbug72994.php on line %d -bool(false) -===DONE=== diff --git a/ext/mbstring/tests/mb_ereg_replace_variation1.phpt b/ext/mbstring/tests/mb_ereg_replace_variation1.phpt index e1c6bffa673..c61e47723d3 100644 --- a/ext/mbstring/tests/mb_ereg_replace_variation1.phpt +++ b/ext/mbstring/tests/mb_ereg_replace_variation1.phpt @@ -96,87 +96,53 @@ foreach($inputs as $input) { echo "Done"; ?> ---EXPECTF-- +--EXPECT-- *** Testing mb_ereg_replace() : usage variations *** -- Iteration 1 -- - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d string(10) "string_val" -- Iteration 2 -- - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d string(10) "string_val" -- Iteration 3 -- - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d string(10) "string_val" -- Iteration 4 -- - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d - -Warning: mb_ereg_replace(): mbregex compile err: invalid code point value in %s on line %d -bool(false) +string(10) "string_val" -- Iteration 5 -- - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d string(10) "string_val" -- Iteration 6 -- - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d - -Warning: mb_ereg_replace(): mbregex compile err: invalid code point value in %s on line %d -bool(false) +string(10) "string_val" -- Iteration 7 -- - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d string(10) "string_val" -- Iteration 8 -- - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d string(10) "string_val" -- Iteration 9 -- - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d string(10) "string_val" -- Iteration 10 -- - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d -string(10) "string_val" +string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val" -- Iteration 11 -- - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d -string(10) "string_val" +string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val" -- Iteration 12 -- - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d string(10) "string_val" -- Iteration 13 -- - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d -string(10) "string_val" +string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val" -- Iteration 14 -- - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d string(10) "string_val" -- Iteration 15 -- - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d -string(10) "string_val" +string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val" -- Iteration 16 -- string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val" @@ -194,17 +160,11 @@ string(10) "string_val" string(10) "string_val" -- Iteration 21 -- - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d string(10) "string_val" -- Iteration 22 -- - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d -string(10) "string_val" +string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val" -- Iteration 23 -- - -Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d -string(10) "string_val" +string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val" Done