Skip to content

Allow all scalar types in ini_set() #6680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)) {
Expand All @@ -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);
}
/* }}} */

Expand Down
2 changes: 1 addition & 1 deletion ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ function ini_get(string $option): string|false {}

function ini_get_all(?string $extension = null, bool $details = true): array|false {}

function ini_set(string $option, string $value): string|false {}
function ini_set(string $option, string|int|float|bool|null $value): string|false {}

/** @alias ini_set */
function ini_alter(string $option, string $value): string|false {}
Expand Down
9 changes: 6 additions & 3 deletions ext/standard/basic_functions_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 4f4ed195a688735d48aeb3b7cd390d8463a07c26 */
* Stub hash: e9f39cbc595f0f2cdd84e58d4857f9fdb03ff7b7 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
Expand Down Expand Up @@ -491,10 +491,13 @@ ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ini_set, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, option, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0)
ZEND_ARG_TYPE_MASK(0, value, MAY_BE_STRING|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_BOOL|MAY_BE_NULL, NULL)
ZEND_END_ARG_INFO()

#define arginfo_ini_alter arginfo_ini_set
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ini_alter, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, option, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ini_restore, 0, 1, IS_VOID, 0)
ZEND_ARG_TYPE_INFO(0, option, IS_STRING, 0)
Expand Down
29 changes: 29 additions & 0 deletions ext/standard/tests/general_functions/ini_set_types.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
ini_set() accepts non-strings under strict_types
--FILE--
<?php
declare(strict_types=1);

ini_set('docref_root', null);
var_dump(ini_get('docref_root'));
ini_set('html_errors', true);
var_dump(ini_get('html_errors'));
ini_set('html_errors', false);
var_dump(ini_get('html_errors'));
ini_set('precision', 6);
var_dump(ini_get('precision'));
// Are there any float options?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"opcache.jit_prof_threshold" and "session.upload_progress.min_freq" seem to be the only ones looking at https://heap.space/s?refs=OnUpdateReal&project=php-src

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, I search for OnUpdateDouble and OnUpdatFloat ... didn't expect it to be called OnUpdateReal!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are part of optional exts and session.upload_progress.min_freq is PERDIR :/


try {
ini_set('foo', []);
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECT--
string(0) ""
string(1) "1"
string(0) ""
string(1) "6"
ini_set(): Argument #2 ($value) must be of type string|int|float|bool|null