Make mb_ereg_replace() pattern argument a string

This commit is contained in:
Nikita Popov 2019-02-01 15:18:28 +01:00
parent ba5d2e6af3
commit 06ed6b8978
4 changed files with 16 additions and 96 deletions

View file

@ -94,6 +94,9 @@ PHP 8.0 UPGRADE NOTES
. The 'e' modifier for mb_ereg_replace() has been removed. . The 'e' modifier for mb_ereg_replace() has been removed.
mb_ereg_replace_callback() should be used instead. 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: - SPL:
. SplFileObject::fgetss() has been removed. . SplFileObject::fgetss() has been removed.

View file

@ -967,8 +967,6 @@ PHP_FUNCTION(mb_eregi)
/* {{{ _php_mb_regex_ereg_replace_exec */ /* {{{ _php_mb_regex_ereg_replace_exec */
static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOptionType options, int is_callable) static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOptionType options, int is_callable)
{ {
zval *arg_pattern_zval;
char *arg_pattern; char *arg_pattern;
size_t arg_pattern_len; size_t arg_pattern_len;
@ -991,7 +989,6 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
OnigUChar *pos; OnigUChar *pos;
OnigUChar *string_lim; OnigUChar *string_lim;
char *description = NULL; char *description = NULL;
char pat_buf[6];
const mbfl_encoding *enc; 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; size_t option_str_len = 0;
if (!is_callable) { if (!is_callable) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zss|s", if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss|s",
&arg_pattern_zval, &arg_pattern, &arg_pattern_len,
&replace, &replace_len, &replace, &replace_len,
&string, &string_len, &string, &string_len,
&option_str, &option_str_len) == FAILURE) { &option_str, &option_str_len) == FAILURE) {
RETURN_FALSE; RETURN_FALSE;
} }
} else { } else {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zfs|s", if (zend_parse_parameters(ZEND_NUM_ARGS(), "sfs|s",
&arg_pattern_zval, &arg_pattern, &arg_pattern_len,
&arg_replace_fci, &arg_replace_fci_cache, &arg_replace_fci, &arg_replace_fci_cache,
&string, &string_len, &string, &string_len,
&option_str, &option_str_len) == FAILURE) { &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"); php_error_docref(NULL, E_WARNING, "The 'e' option is no longer supported, use mb_ereg_replace_callback instead");
RETURN_FALSE; 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 */ /* create regex pattern buffer */
re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, options, MBREX(current_mbctype), syntax); re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, options, MBREX(current_mbctype), syntax);
if (re == NULL) { if (re == NULL) {

View file

@ -1,21 +0,0 @@
--TEST--
Bug #72994 (mbc_to_code() out of bounds read)
--SKIPIF--
<?php
if (!extension_loaded('mbstring')) die('skip mbstring extension not available');
if (!function_exists('mb_ereg_replace')) die('skip mb_ereg_replace() not available');
?>
--FILE--
<?php
$var1 = mb_ereg_replace($var-232338951,NULL,NULL,NULL);
var_dump($var1);
?>
===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===

View file

@ -96,87 +96,53 @@ foreach($inputs as $input) {
echo "Done"; echo "Done";
?> ?>
--EXPECTF-- --EXPECT--
*** Testing mb_ereg_replace() : usage variations *** *** Testing mb_ereg_replace() : usage variations ***
-- Iteration 1 -- -- 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" string(10) "string_val"
-- Iteration 2 -- -- 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" string(10) "string_val"
-- Iteration 3 -- -- 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" string(10) "string_val"
-- Iteration 4 -- -- Iteration 4 --
string(10) "string_val"
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)
-- Iteration 5 -- -- 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" string(10) "string_val"
-- Iteration 6 -- -- Iteration 6 --
string(10) "string_val"
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)
-- Iteration 7 -- -- 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" string(10) "string_val"
-- Iteration 8 -- -- 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" string(10) "string_val"
-- Iteration 9 -- -- 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" string(10) "string_val"
-- Iteration 10 -- -- Iteration 10 --
string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val"
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 11 -- -- Iteration 11 --
string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val"
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 12 -- -- 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" string(10) "string_val"
-- Iteration 13 -- -- Iteration 13 --
string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val"
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 14 -- -- 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" string(10) "string_val"
-- Iteration 15 -- -- Iteration 15 --
string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val"
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 16 -- -- Iteration 16 --
string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val" 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" string(10) "string_val"
-- Iteration 21 -- -- 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" string(10) "string_val"
-- Iteration 22 -- -- Iteration 22 --
string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val"
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 23 -- -- Iteration 23 --
string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val"
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"
Done Done