Skip to content

Commit 48786b4

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix GH-24308: Preserve syslog handles not opened by PHP (#24310)
2 parents 56e3429 + b0c8e27 commit 48786b4

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ PHP NEWS
113113
file fails after it was already truncated. (Ilia Alshanetsky)
114114

115115
- Standard:
116+
. Fixed bug GH-24308 (Request shutdown calls closelog() even when syslog
117+
was not opened by PHP). (lazerg)
116118
. Fixed password_get_info() and password_needs_rehash() accepting malformed
117119
bcrypt costs. (Ilia Alshanetsky)
118120
. Fixed proc_open() null descriptor not being inheritable on Windows.

‎ext/standard/syslog.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ PHP_MINIT_FUNCTION(syslog)
4141

4242
PHP_RSHUTDOWN_FUNCTION(syslog)
4343
{
44-
php_closelog();
44+
if (PG(have_called_openlog)) {
45+
php_closelog();
46+
}
4547
if (BG(syslog_device)) {
4648
free(BG(syslog_device));
4749
BG(syslog_device) = NULL;
@@ -102,6 +104,9 @@ PHP_FUNCTION(syslog)
102104
Z_PARAM_STR(message)
103105
ZEND_PARSE_PARAMETERS_END();
104106

107+
if (!PG(have_called_openlog)) {
108+
php_openlog(PG(syslog_ident), 0, PG(syslog_facility));
109+
}
105110
php_syslog_str(priority, message);
106111
RETURN_TRUE;
107112
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
GH-24308 (syslog() without openlog() is closed at request end)
3+
--SKIPIF--
4+
<?php
5+
if (PHP_OS_FAMILY !== 'Linux') die('skip Linux only');
6+
if (!@is_dir('/proc/self/fd')) die('skip requires /proc/self/fd');
7+
if (!@stream_socket_client('udg:///dev/log')) die('skip requires /dev/log');
8+
?>
9+
--FILE--
10+
<?php
11+
$serverCode = <<<'CODE'
12+
function sockets() {
13+
$sockets = [];
14+
foreach (scandir('/proc/self/fd') as $fd) {
15+
$link = @readlink("/proc/self/fd/$fd");
16+
if ($link !== false && str_starts_with($link, 'socket:')) {
17+
$sockets[$fd] = $link;
18+
}
19+
}
20+
return $sockets;
21+
}
22+
23+
if (isset($_GET['syslog'])) {
24+
$before = sockets();
25+
syslog(LOG_DEBUG, 'GH-24308');
26+
echo json_encode(array_diff_assoc(sockets(), $before));
27+
} else {
28+
echo json_encode(sockets());
29+
}
30+
CODE;
31+
32+
include __DIR__."/../../../../sapi/cli/tests/php_cli_server.inc";
33+
php_cli_server_start($serverCode, null, []);
34+
35+
$opened = json_decode(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS . "/?syslog"), true);
36+
var_dump(count($opened));
37+
38+
$next = json_decode(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS . "/"), true);
39+
var_dump(array_intersect_assoc($opened, $next));
40+
?>
41+
--EXPECT--
42+
int(1)
43+
array(0) {
44+
}

0 commit comments

Comments
 (0)