diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2021-02-11 10:42:55 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2021-02-11 15:01:16 +0100 |
commit | 070e24d7a91a49fce56b5ee4d5a102d022d3e724 (patch) | |
tree | d9bd7c9fbf0cba6b62a7f37f5d24ecf2320f90e0 /ext/standard/basic_functions.c | |
parent | dcf389228c9f1f65da9983226cfe5e6ca6904298 (diff) | |
download | php-git-070e24d7a91a49fce56b5ee4d5a102d022d3e724.tar.gz |
Allow all scalar types in ini_set()
This changes ini_set() to accept all scalar types
(string|int|float|bool|null) for the new value. The idea here is
that while the INI system ultimately works with strings, its value
interpretation is designed to be consistent with PHP's casting rules,
e.g. "1" and "" are interpreted as boolean true and false respectively.
I personally believe that writing ini_set('precision', 10) makes more
sense than ini_set('precision', '10'), and find strict_types to be
unnecessarily pedantic here.
Closes GH-6680.
Diffstat (limited to 'ext/standard/basic_functions.c')
-rwxr-xr-x | ext/standard/basic_functions.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 54c3188771..4084f5d853 100755 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -2086,14 +2086,19 @@ static int php_ini_check_path(char *option_name, size_t option_len, char *new_op PHP_FUNCTION(ini_set) { zend_string *varname; - zend_string *new_value; + zval *new_value; zend_string *val; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_STR(varname) - Z_PARAM_STR(new_value) + Z_PARAM_ZVAL(new_value) ZEND_PARSE_PARAMETERS_END(); + if (Z_TYPE_P(new_value) > IS_STRING) { + zend_argument_type_error(2, "must be of type string|int|float|bool|null"); + RETURN_THROWS(); + } + val = zend_ini_get_value(varname); if (val) { @@ -2102,6 +2107,9 @@ PHP_FUNCTION(ini_set) RETVAL_FALSE; } + zend_string *new_value_tmp_str; + zend_string *new_value_str = zval_get_tmp_string(new_value, &new_value_tmp_str); + #define _CHECK_PATH(var, var_len, ini) php_ini_check_path(var, var_len, ini, sizeof(ini)) /* open basedir check */ if (PG(open_basedir)) { @@ -2111,18 +2119,20 @@ PHP_FUNCTION(ini_set) _CHECK_PATH(ZSTR_VAL(varname), ZSTR_LEN(varname), "mail.log") || _CHECK_PATH(ZSTR_VAL(varname), ZSTR_LEN(varname), "java.library.path") || _CHECK_PATH(ZSTR_VAL(varname), ZSTR_LEN(varname), "vpopmail.directory")) { - if (php_check_open_basedir(ZSTR_VAL(new_value))) { + if (php_check_open_basedir(ZSTR_VAL(new_value_str))) { zval_ptr_dtor_str(return_value); + zend_tmp_string_release(new_value_tmp_str); RETURN_FALSE; } } } #undef _CHECK_PATH - if (zend_alter_ini_entry_ex(varname, new_value, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0) == FAILURE) { + if (zend_alter_ini_entry_ex(varname, new_value_str, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0) == FAILURE) { zval_ptr_dtor_str(return_value); - RETURN_FALSE; + RETVAL_FALSE; } + zend_tmp_string_release(new_value_tmp_str); } /* }}} */ |