From eda05cfbffe314a1d68dea6789e9ee1e7ec9cf79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 9 Jan 2025 19:49:30 +0100 Subject: [PATCH 1/3] sapi/cli: Extend `--ini` to print INI settings changed from the builtin default This is intended to make it easier to check whether or not a given INI setting is changed from the default when building reproducers for a bugreport, without forgetting any that might be relevant to the report. As an example, running `sapi/cli/php -c /etc/php/8.3/cli/ --ini` on my Ubuntu will now output: Configuration File (php.ini) Path: /usr/local/lib Loaded Configuration File: /etc/php/8.3/cli/php.ini Scan for additional .ini files in: (none) Additional .ini files parsed: (none) Non-standard INI settings: allow_url_include: "0" -> "" auto_append_file: (none) -> "" auto_prepend_file: (none) -> "" display_errors: "1" -> "" display_startup_errors: "1" -> "" enable_dl: "1" -> "" error_reporting: (none) -> "22527" html_errors: "1" -> "0" ignore_repeated_errors: "0" -> "" ignore_repeated_source: "0" -> "" implicit_flush: "0" -> "1" log_errors: "0" -> "1" mail.add_x_header: "0" -> "" mail.mixed_lf_and_crlf: "0" -> "" max_execution_time: "30" -> "0" memory_limit: "128M" -> "-1" request_order: (none) -> "GP" session.cookie_httponly: "0" -> "" session.gc_divisor: "100" -> "1000" session.gc_probability: "1" -> "0" session.sid_bits_per_character: "4" -> "5" session.sid_length: "32" -> "26" short_open_tag: "1" -> "" unserialize_callback_func: (none) -> "" user_dir: (none) -> "" variables_order: "EGPCS" -> "GPCS" zend.assertions: "1" -> "-1" zend.exception_ignore_args: "0" -> "1" zend.exception_string_param_max_len: "15" -> "0" --- Zend/zend_ini.c | 1 + Zend/zend_ini.h | 1 + sapi/cli/php_cli.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/Zend/zend_ini.c b/Zend/zend_ini.c index b4c0722e3e94..7039686ec33b 100644 --- a/Zend/zend_ini.c +++ b/Zend/zend_ini.c @@ -225,6 +225,7 @@ ZEND_API zend_result zend_register_ini_entries_ex(const zend_ini_entry_def *ini_ while (ini_entry->name) { p = pemalloc(sizeof(zend_ini_entry), 1); + p->def = ini_entry; p->name = zend_string_init_interned(ini_entry->name, ini_entry->name_length, 1); p->on_modify = ini_entry->on_modify; p->mh_arg1 = ini_entry->mh_arg1; diff --git a/Zend/zend_ini.h b/Zend/zend_ini.h index 1939d7b89e3f..5a7377f1181d 100644 --- a/Zend/zend_ini.h +++ b/Zend/zend_ini.h @@ -60,6 +60,7 @@ struct _zend_ini_entry { uint8_t orig_modifiable; uint8_t modified; + const zend_ini_entry_def *def; }; BEGIN_EXTERN_C() diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 941fab1c08d7..8bf26ffc090c 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -588,6 +588,14 @@ BOOL WINAPI php_cli_win32_ctrl_handler(DWORD sig) #endif /*}}}*/ +static int zend_ini_entry_cmp(Bucket *a, Bucket *b) +{ + zend_ini_entry *A = Z_PTR(a->val); + zend_ini_entry *B = Z_PTR(b->val); + + return zend_binary_strcasecmp(ZSTR_VAL(A->name), ZSTR_LEN(A->name), ZSTR_VAL(B->name), ZSTR_LEN(B->name)); +} + static int do_cli(int argc, char **argv) /* {{{ */ { int c; @@ -1096,6 +1104,31 @@ static int do_cli(int argc, char **argv) /* {{{ */ zend_printf("Loaded Configuration File: %s\n", php_ini_opened_path ? php_ini_opened_path : "(none)"); zend_printf("Scan for additional .ini files in: %s\n", php_ini_scanned_path ? php_ini_scanned_path : "(none)"); zend_printf("Additional .ini files parsed: %s\n", php_ini_scanned_files ? php_ini_scanned_files : "(none)"); + zend_printf("\n"); + zend_printf("Non-standard INI settings:\n"); + zend_ini_entry *ini_entry; + HashTable *sorted = zend_array_dup(EG(ini_directives)); + zend_array_sort(sorted, zend_ini_entry_cmp, 1); + ZEND_HASH_PACKED_FOREACH_PTR(sorted, ini_entry) { + if (ini_entry->value == NULL && ini_entry->def->value == NULL) { + continue; + } + if (ini_entry->value != NULL && ini_entry->def->value != NULL && zend_string_equals_cstr(ini_entry->value, ini_entry->def->value, ini_entry->def->value_length)) { + continue; + } + + zend_printf( + "%s: %s%s%s -> %s%s%s\n", + ZSTR_VAL(ini_entry->name), + ini_entry->def->value ? "\"" : "", + ini_entry->def->value ? ini_entry->def->value : "(none)", + ini_entry->def->value ? "\"" : "", + ini_entry->value ? "\"" : "", + ini_entry->value ? ZSTR_VAL(ini_entry->value) : "(none)", + ini_entry->value ? "\"" : "" + ); + } ZEND_HASH_FOREACH_END(); + zend_array_destroy(sorted); break; } } From 3f607eeb095d02e4a56377e1bb86c71764432f28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 27 Jan 2025 13:39:05 +0100 Subject: [PATCH 2/3] Improve phrasing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michael Voříšek --- sapi/cli/php_cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 8bf26ffc090c..49b2dd2e5b9e 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -1105,7 +1105,7 @@ static int do_cli(int argc, char **argv) /* {{{ */ zend_printf("Scan for additional .ini files in: %s\n", php_ini_scanned_path ? php_ini_scanned_path : "(none)"); zend_printf("Additional .ini files parsed: %s\n", php_ini_scanned_files ? php_ini_scanned_files : "(none)"); zend_printf("\n"); - zend_printf("Non-standard INI settings:\n"); + zend_printf("Non-default INI settings:\n"); zend_ini_entry *ini_entry; HashTable *sorted = zend_array_dup(EG(ini_directives)); zend_array_sort(sorted, zend_ini_entry_cmp, 1); From 705b28dc2d87d0d84e679224e09ae1000352d750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 5 Feb 2025 17:16:34 +0100 Subject: [PATCH 3/3] NEWS/UPGRADING --- NEWS | 4 ++++ UPGRADING | 1 + 2 files changed, 5 insertions(+) diff --git a/NEWS b/NEWS index 5148521e0790..5b21c028d391 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 8.5.0alpha1 +- CLI: + . Extended --ini to print INI settings changed from the builtin default. + (timwolla) + - COM: . Fixed property access of PHP objects wrapped in variant. (cmb) . Fixed method calls for PHP objects wrapped in variant. (cmb) diff --git a/UPGRADING b/UPGRADING index c35d9477af89..7149579d4732 100644 --- a/UPGRADING +++ b/UPGRADING @@ -107,6 +107,7 @@ PHP 8.5 UPGRADE NOTES - CLI: . Trying to set a process title that is too long with cli_set_process_title() will now fail instead of silently truncating the given title. + . --ini will now print INI settings changed from the builtin default. ======================================== 4. Deprecated Functionality