[php-src] master: Merge branch 'PHP-8.5' into PHP-8.6
| From: | Weilin Du | Date: | Fri, 23 Oct 2026 16:50:59 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.5' into PHP-8.6 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-142631@lists.php.net to get a copy of this message | ||
Author: Weilin Du (LamentXU123)
Date: 2026-10-24T00:40:46+08:00
Commit: https://github.com/php/php-src/commit/13f0820058ced987a0f2371a44462a702304c7fb
Raw diff: https://github.com/php/php-src/commit/13f0820058ced987a0f2371a44462a702304c7fb.diff
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
Fix GH-24308: Preserve syslog handles not opened by PHP (#24310)
Changed paths:
A ext/standard/tests/network/gh24308.phpt
M NEWS
M ext/standard/syslog.c
Diff:
diff --git a/NEWS b/NEWS
index 335f854375cf..42ff62143cff 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,10 @@ PHP NEWS
. Fixed infinite loop in sapi_header_op() for headers of 4 GiB or more.
(Martin Mirchev)
+- Standard:
+ . Fixed bug GH-24308 (Request shutdown calls closelog() even when syslog
+ was not opened by PHP). (lazerg)
+
- Streams:
. Fixed bug GH-24506 (stream_select() leaks a stream-error operation level
on its FD_SETSIZE failure path). (azjezz)
diff --git a/ext/standard/syslog.c b/ext/standard/syslog.c
index 78dfb2297fdc..0dfe5bdf8c33 100644
--- a/ext/standard/syslog.c
+++ b/ext/standard/syslog.c
@@ -39,7 +39,9 @@ PHP_MINIT_FUNCTION(syslog)
PHP_RSHUTDOWN_FUNCTION(syslog)
{
- php_closelog();
+ if (PG(have_called_openlog)) {
+ php_closelog();
+ }
if (BG(syslog_device)) {
free(BG(syslog_device));
BG(syslog_device) = NULL;
@@ -100,6 +102,9 @@ PHP_FUNCTION(syslog)
Z_PARAM_STR(message)
ZEND_PARSE_PARAMETERS_END();
+ if (!PG(have_called_openlog)) {
+ php_openlog(PG(syslog_ident), 0, PG(syslog_facility));
+ }
php_syslog_str(priority, message);
RETURN_TRUE;
}
diff --git a/ext/standard/tests/network/gh24308.phpt b/ext/standard/tests/network/gh24308.phpt
new file mode 100644
index 000000000000..bfb50ae95e40
--- /dev/null
+++ b/ext/standard/tests/network/gh24308.phpt
@@ -0,0 +1,44 @@
+--TEST--
+GH-24308 (syslog() without openlog() is closed at request end)
+--SKIPIF--
+<?php
+if (PHP_OS_FAMILY !== 'Linux') die('skip Linux only');
+if (!@is_dir('/proc/self/fd')) die('skip requires /proc/self/fd');
+if (!@stream_socket_client('udg:///dev/log')) die('skip requires /dev/log');
+?>
+--FILE--
+<?php
+$serverCode = <<<'CODE'
+function sockets() {
+ $sockets = [];
+ foreach (scandir('/proc/self/fd') as $fd) {
+ $link = @readlink("/proc/self/fd/$fd");
+ if ($link !== false && str_starts_with($link, 'socket:')) {
+ $sockets[$fd] = $link;
+ }
+ }
+ return $sockets;
+}
+
+if (isset($_GET['syslog'])) {
+ $before = sockets();
+ syslog(LOG_DEBUG, 'GH-24308');
+ echo json_encode(array_diff_assoc(sockets(), $before));
+} else {
+ echo json_encode(sockets());
+}
+CODE;
+
+include __DIR__."/../../../../sapi/cli/tests/php_cli_server.inc";
+php_cli_server_start($serverCode, null, []);
+
+$opened = json_decode(file_get_contents("http://" .
PHP_CLI_SERVER_ADDRESS . "/?syslog"), true);
+var_dump(count($opened));
+
+$next = json_decode(file_get_contents("http://" .
PHP_CLI_SERVER_ADDRESS . "/"), true);
+var_dump(array_intersect_assoc($opened, $next));
+?>
+--EXPECT--
+int(1)
+array(0) {
+}