[php-src] PHP-8.2: Fix GH-13563: Setting bool values via env in FPM config fails

From: Date: Thu, 28 Mar 2024 15:44:40 +0000
Subject: [php-src] PHP-8.2: Fix GH-13563: Setting bool values via env in FPM config fails
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-127872@lists.php.net to get a copy of this message
Author: Jakub Zelenka (bukka) Date: 2024-03-28T15:43:50Z Commit: https://github.com/php/php-src/commit/d0a8d41eee1912613d33a92e2a0839d3cdb90b5d Raw diff: https://github.com/php/php-src/commit/d0a8d41eee1912613d33a92e2a0839d3cdb90b5d.diff Fix GH-13563: Setting bool values via env in FPM config fails Closes GH-13786 Changed paths: A sapi/fpm/tests/gh13563-conf-bool-env.phpt M NEWS M sapi/fpm/fpm/fpm_conf.c M sapi/fpm/tests/tester.inc Diff: diff --git a/NEWS b/NEWS index bdc2cd8efa244..86dccc9a06d03 100644 --- a/NEWS +++ b/NEWS @@ -18,7 +18,9 @@ PHP NEWS . Fix phpdoc for DOMDocument load methods. (VincentLanglet) - FPM - . Fix incorrect check in fpm_shm_free(). (nielsdos) + . Fixed incorrect check in fpm_shm_free(). (nielsdos) + . Fixed bug GH-13563 (Setting bool values via env in FPM config fails). + (Jakub Zelenka) - GD: . Fixed bug GH-12019 (add GDLIB_CFLAGS in feature tests). (Michael Orlitzky) diff --git a/sapi/fpm/fpm/fpm_conf.c b/sapi/fpm/fpm/fpm_conf.c index ef9b35a9994aa..e1aec90ff3e83 100644 --- a/sapi/fpm/fpm/fpm_conf.c +++ b/sapi/fpm/fpm/fpm_conf.c @@ -213,8 +213,22 @@ static int fpm_conf_expand_pool_name(char **value) { static char *fpm_conf_set_boolean(zval *value, void **config, intptr_t offset) /* {{{ */ { zend_string *val = Z_STR_P(value); - bool value_y = zend_string_equals_literal(val, "1"); - bool value_n = ZSTR_LEN(val) == 0; /* Empty string is the only valid false value */ + /* we need to check all allowed values to correctly set value from the environment variable */ + bool value_y = ( + zend_string_equals_literal(val, "1") || + zend_string_equals_literal(val, "yes") || + zend_string_equals_literal(val, "true") || + zend_string_equals_literal(val, "on") + ); + bool value_n = ( + value_y || ZSTR_LEN(val) == 0 || + zend_string_equals_literal(val, "0") || + zend_string_equals_literal(val, "no") || + zend_string_equals_literal(val, "none") || + zend_string_equals_literal(val, "false") || + zend_string_equals_literal(val, "off") + ); + if (!value_y && !value_n) { return "invalid boolean value"; diff --git a/sapi/fpm/tests/gh13563-conf-bool-env.phpt b/sapi/fpm/tests/gh13563-conf-bool-env.phpt new file mode 100644 index 0000000000000..15dce0ecf9b5a --- /dev/null +++ b/sapi/fpm/tests/gh13563-conf-bool-env.phpt @@ -0,0 +1,75 @@ +--TEST-- +FPM: GH-13563 - conf boolean environment variables values +--SKIPIF-- +<?php +include "skipif.inc"; +FPM\Tester::skipIfRoot(); +?> +--FILE-- +<?php + +require_once "tester.inc"; + +$cfg = <<<EOT +[global] +error_log = {{FILE:LOG}} +log_limit = 1024 +log_buffering = \${FPM_TEST_LOG_BUF} +daemonize = \${FPM_TEST_DAEMONIZE} +[unconfined] +listen = {{ADDR}} +process.dumpable = \${FPM_TEST_PROC_DUMP} +pm = dynamic +pm.max_children = 5 +pm.start_servers = 1 +pm.min_spare_servers = 1 +pm.max_spare_servers = 3 +request_terminate_timeout_track_finished = \${FPM_TEST_REQ_TERM_TRACK_FIN} +catch_workers_output = \${FPM_TEST_CATCH_WRK_OUT} +decorate_workers_output = \${FPM_TEST_DECOR_WRK_OUT} +clear_env = \${FPM_TEST_CLEAR_ENV} +EOT; + +$code = <<<EOT +<?php +foreach (getenv() as \$name => \$val) { + if (str_starts_with(\$name, 'FPM_TEST')) { + printf("%s: %s\n", \$name, \$val); + } +} +file_put_contents('php://stderr', str_repeat('a', 20) . "\n"); +EOT; + +$tester = new FPM\Tester($cfg, $code); +$tester->start(envVars: [ + 'FPM_TEST_LOG_BUF' => 'on', + 'FPM_TEST_DAEMONIZE' => 'false', + 'FPM_TEST_PROC_DUMP' => 'no', + 'FPM_TEST_CATCH_WRK_OUT' => 'yes', + 'FPM_TEST_DECOR_WRK_OUT' => 'true', + 'FPM_TEST_CLEAR_ENV' => 'none', + 'FPM_TEST_REQ_TERM_TRACK_FIN' => '0', +]); +$tester->expectLogStartNotices(); +$tester->request()->expectBody([ + 'FPM_TEST_LOG_BUF: on', + 'FPM_TEST_DAEMONIZE: false', + 'FPM_TEST_PROC_DUMP: no', + 'FPM_TEST_CATCH_WRK_OUT: yes', + 'FPM_TEST_DECOR_WRK_OUT: true', + 'FPM_TEST_CLEAR_ENV: none', + 'FPM_TEST_REQ_TERM_TRACK_FIN: 0', +]); +$tester->terminate(); +$tester->expectLogMessage('a', 1024, 20, true); +$tester->close(); + +?> +Done +--EXPECT-- +Done +--CLEAN-- +<?php +require_once "tester.inc"; +FPM\Tester::clean(); +?> diff --git a/sapi/fpm/tests/tester.inc b/sapi/fpm/tests/tester.inc index 66cbad175298d..ff834c329fa50 100644 --- a/sapi/fpm/tests/tester.inc +++ b/sapi/fpm/tests/tester.inc @@ -432,6 +432,7 @@ class Tester bool $daemonize = false, array $extensions = [], array $iniEntries = [], + array $envVars = [], ) { $configFile = $this->createConfig(); $desc = $this->outDesc ? [] : [1 => array('pipe', 'w'), 2 => array('redirect', 1)]; @@ -465,7 +466,7 @@ class Tester $cmd = array_merge($cmd, $extraArgs); $this->trace('Starting FPM using command:', $cmd, true); - $this->masterProcess = proc_open($cmd, $desc, $pipes); + $this->masterProcess = proc_open($cmd, $desc, $pipes, null, $envVars); register_shutdown_function( function ($masterProcess) use ($configFile) { @unlink($configFile);

« previous php.cvs (#127872) next »