[php-src] master: Merge branch 'PHP-8.6'

From: Date: Tue, 27 Oct 2026 16:08:17 +0000
Subject: [php-src] master: Merge branch 'PHP-8.6'
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-142823@lists.php.net to get a copy of this message
Author: Jakub Zelenka (bukka) Date: 2026-10-27T17:08:05+01:00 Commit: https://github.com/php/php-src/commit/1ed9d6acdfec320c00f2480a8620bce497f61f08 Raw diff: https://github.com/php/php-src/commit/1ed9d6acdfec320c00f2480a8620bce497f61f08.diff Merge branch 'PHP-8.6' * PHP-8.6: Fix FPM worker output prefix longer than its buffer or log_limit Changed paths: A sapi/fpm/tests/log-bwd-long-pool-name.phpt A sapi/fpm/tests/log-dwd-long-pool-name-limit-512.phpt M sapi/fpm/fpm/zlog.c Diff: diff --git a/sapi/fpm/fpm/zlog.c b/sapi/fpm/fpm/zlog.c index b34d455e6bd6..f11618b94773 100644 --- a/sapi/fpm/fpm/zlog.c +++ b/sapi/fpm/fpm/zlog.c @@ -609,6 +609,7 @@ zlog_bool zlog_stream_set_msg_prefix(struct zlog_stream *stream, const char *fmt { char buf[MAX_WRAPPING_PREFIX_LENGTH]; size_t len; + int written; va_list args; if (!stream->decorate) { @@ -616,9 +617,16 @@ zlog_bool zlog_stream_set_msg_prefix(struct zlog_stream *stream, const char *fmt } va_start(args, fmt); - len = vsnprintf(buf, MAX_WRAPPING_PREFIX_LENGTH - 1, fmt, args); + written = vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); + if (written < 0) { + return ZLOG_FALSE; + } + /* Use only what was written to buf, and keep at least half of the log line + * for the time and level prefix and the message itself. */ + len = MIN((size_t) written, MIN(sizeof(buf) - 1, (size_t) zlog_limit / 2)); + if (stream->msg_prefix_len < len) { stream->msg_prefix = stream->msg_prefix_len ? realloc(stream->msg_prefix, len + 1) : malloc(len + 1); if (stream->msg_prefix == NULL) { @@ -629,7 +637,7 @@ zlog_bool zlog_stream_set_msg_prefix(struct zlog_stream *stream, const char *fmt stream->msg_prefix[len] = 0; stream->msg_prefix_len = len; - return len; + return ZLOG_TRUE; } /* }}} */ @@ -748,7 +756,10 @@ ssize_t zlog_stream_vformat(struct zlog_stream *stream, const char *fmt, va_list char sbuf[1024]; size_t len; - len = vsnprintf(sbuf, 1024, fmt, args); + len = vsnprintf(sbuf, sizeof(sbuf), fmt, args); + if (len >= sizeof(sbuf)) { + len = sizeof(sbuf) - 1; + } return zlog_stream_str(stream, sbuf, len); } diff --git a/sapi/fpm/tests/log-bwd-long-pool-name.phpt b/sapi/fpm/tests/log-bwd-long-pool-name.phpt new file mode 100644 index 000000000000..47c09f5cbfe0 --- /dev/null +++ b/sapi/fpm/tests/log-bwd-long-pool-name.phpt @@ -0,0 +1,45 @@ +--TEST-- +FPM: Buffered worker output decorated log with pool name longer than the message prefix buffer +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php + +require_once "tester.inc"; + +$pool = str_repeat('p', 600); + +$cfg = <<<EOT +[global] +error_log = {{FILE:LOG}} +[$pool] +listen = {{ADDR}} +pm = static +pm.max_children = 1 +catch_workers_output = yes +EOT; + +$code = <<<EOT +<?php +file_put_contents('php://stderr', "msg 1\n"); +EOT; + +$tester = new FPM\Tester($cfg, $code); +$tester->start(); +$tester->expectLogStartNotices(); +$tester->request()->expectEmptyBody(); +/* The message prefix is truncated to 511 bytes. */ +$tester->expectLogPattern('/^\[[^\]]+\] WARNING: \[pool p{505}"msg 1"$/'); +$tester->terminate(); +$tester->expectLogTerminatingNotices(); +$tester->close(); + +?> +Done +--EXPECT-- +Done +--CLEAN-- +<?php +require_once "tester.inc"; +FPM\Tester::clean(); +?> diff --git a/sapi/fpm/tests/log-dwd-long-pool-name-limit-512.phpt b/sapi/fpm/tests/log-dwd-long-pool-name-limit-512.phpt new file mode 100644 index 000000000000..ffd099cb3bd6 --- /dev/null +++ b/sapi/fpm/tests/log-dwd-long-pool-name-limit-512.phpt @@ -0,0 +1,47 @@ +--TEST-- +FPM: Direct worker output decorated log with pool name longer than log_limit +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php + +require_once "tester.inc"; + +$pool = str_repeat('p', 1100); + +$cfg = <<<EOT +[global] +error_log = {{FILE:LOG}} +log_limit = 512 +log_buffering = no +[$pool] +listen = {{ADDR}} +pm = static +pm.max_children = 1 +catch_workers_output = yes +EOT; + +$code = <<<EOT +<?php +file_put_contents('php://stderr', "msg 1\n"); +EOT; + +$tester = new FPM\Tester($cfg, $code); +$tester->start(); +$tester->expectLogStartNotices(); +$tester->request()->expectEmptyBody(); +/* The message prefix is truncated to half of log_limit. */ +$tester->expectLogPattern('/^\[[^\]]+\] WARNING: \[pool p{250}"msg 1"$/'); +$tester->terminate(); +$tester->expectLogTerminatingNotices(); +$tester->close(); + +?> +Done +--EXPECT-- +Done +--CLEAN-- +<?php +require_once "tester.inc"; +FPM\Tester::clean(); +?>

« previous php.cvs (#142823) next »