[php-src] PHP-8.3: Merge branch 'PHP-8.2' into PHP-8.3
| From: | Jakub Zelenka | Date: | Thu, 28 Mar 2024 15:45:57 +0000 |
| Subject: | [php-src] PHP-8.3: Merge branch 'PHP-8.2' into PHP-8.3 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-127873@lists.php.net to get a copy of this message | ||
Author: Jakub Zelenka (bukka)
Date: 2024-03-28T15:45:45Z
Commit: https://github.com/php/php-src/commit/8edd6215015741d6f3dca9b49ff821cb6d654a93
Raw diff: https://github.com/php/php-src/commit/8edd6215015741d6f3dca9b49ff821cb6d654a93.diff
Merge branch 'PHP-8.2' into PHP-8.3
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 d15da21f785da..361a896d8d0b4 100644
--- a/NEWS
+++ b/NEWS
@@ -25,7 +25,9 @@ PHP NEWS
- FPM:
. Fixed GH-11086 (FPM: config test runs twice in daemonised mode).
(Jakub Zelenka)
- . 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 4823c039b059b..d128681eaf517 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 d5dbdd36ff1a2..b4700c019c6cc 100644
--- a/sapi/fpm/tests/tester.inc
+++ b/sapi/fpm/tests/tester.inc
@@ -514,6 +514,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)];
@@ -547,7 +548,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);