Commit 0ccf33ad547 for php

commit 0ccf33ad5474b30bd758c979e8072321ec354adc
Author: Jorg Sowa <jorg.sowa@gmail.com>
Date:   Wed Nov 25 18:02:40 2026 +0100

    Fix FPM log overflow when errno text exceeds the buffer (GH-25648)

    With log_limit above 2048, vzlog() checked the length after appending
    errno text only against log_limit. snprintf() returns the would-be
    length, so a message nearly filling the 2048-byte stack buffer made the
    newline write and the log write go past it. Truncate when the buffer
    size is reached too.

    Closes GH-25648

diff --git a/NEWS b/NEWS
index 3cdfc796952..7f78337562e 100644
--- a/NEWS
+++ b/NEWS
@@ -71,6 +71,10 @@ PHP                                                                        NEWS
   . Fixed stack overflow in filter_var() and filter_var_array() with deeply
     nested arrays. (Eyüp Can Akman)

+- FPM:
+  . Fixed stack buffer overflow when logging an error with errno text and
+    log_limit above 2048. (Jorg Sowa)
+
 - GD:
   . Fixed use-after-free when drawing with a brush or tile image that was
     released after imagesetbrush() or imagesettile(). (lacatoire)
diff --git a/sapi/fpm/fpm/zlog.c b/sapi/fpm/fpm/zlog.c
index 0f89c75b35a..97bb280217b 100644
--- a/sapi/fpm/fpm/zlog.c
+++ b/sapi/fpm/fpm/zlog.c
@@ -227,7 +227,7 @@ void vzlog(const char *function, int line, int flags, const char *fmt, va_list a
 		if (flags & ZLOG_HAVE_ERRNO) {
 			len += snprintf(buf + len, buf_size - len,
 					": %s (%d)", strerror(saved_errno), saved_errno);
-			if (len >= zlog_limit) {
+			if (len >= zlog_limit || len >= buf_size) {
 				truncated = 1;
 			}
 		}
diff --git a/sapi/fpm/tests/log-limit-above-buffer-errno-msg.phpt b/sapi/fpm/tests/log-limit-above-buffer-errno-msg.phpt
new file mode 100644
index 00000000000..641d2ada4aa
--- /dev/null
+++ b/sapi/fpm/tests/log-limit-above-buffer-errno-msg.phpt
@@ -0,0 +1,38 @@
+--TEST--
+FPM: Log message with errno is truncated to the buffer when log_limit is above it
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--FILE--
+<?php
+
+require_once "tester.inc";
+
+/* The error line nearly fills the 2048-byte log buffer before errno text is appended. */
+$slowlog = '/' . str_repeat('a', 1970);
+
+$cfg = <<<EOT
+[global]
+error_log = {{FILE:LOG}}
+log_limit = 4096
+[unconfined]
+listen = {{ADDR}}
+pm = static
+pm.max_children = 1
+request_slowlog_timeout = 1
+slowlog = $slowlog
+EOT;
+
+$tester = new FPM\Tester($cfg);
+$tester->start();
+$tester->expectLogPattern('/^\[[^\]]+\] ERROR: Unable to create or open slowlog\(\/a{1970}\): .{7}\.\.\.$/');
+$tester->close(true);
+
+?>
+Done
+--EXPECT--
+Done
+--CLEAN--
+<?php
+require_once "tester.inc";
+FPM\Tester::clean();
+?>