diff --git a/sapi/fpm/fpm/fpm_conf.c b/sapi/fpm/fpm/fpm_conf.c index ef9b35a9994aa..a7aa900d3c479 100644 --- a/sapi/fpm/fpm/fpm_conf.c +++ b/sapi/fpm/fpm/fpm_conf.c @@ -213,8 +213,21 @@ 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 alowed values to correctly set value from the environment varaible */ + 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, "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..6f53bf0393cb9 --- /dev/null +++ b/sapi/fpm/tests/gh13563-conf-bool-env.phpt @@ -0,0 +1,72 @@ +--TEST-- +FPM: GH-13563 - conf boolean environment variables values +--SKIPIF-- + +--FILE-- + \$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', +]); +$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', +]); +$tester->terminate(); +$tester->expectLogMessage('a', 1024, 20, true); +$tester->close(); + +?> +Done +--EXPECT-- +Done +--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);