Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ PHP NEWS
when getpwnam_r() needs a larger buffer. (Ilia Alshanetsky)
. Fixed password_get_info() and password_needs_rehash() accepting malformed
bcrypt costs. (Ilia Alshanetsky)
. Fixed bug GH-24308 (Request shutdown calls closelog() even when syslog
was not opened by PHP). (lazerg)

- Zip:
. Fixed use-after-free when re-entering ZipArchive during destruction or
Expand Down
7 changes: 6 additions & 1 deletion ext/standard/syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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;
Expand Down Expand Up @@ -102,6 +104,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;
}
Expand Down
44 changes: 44 additions & 0 deletions ext/standard/tests/network/gh24308.phpt
Original file line number Diff line number Diff line change
@@ -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) {
}
Loading