diff --git a/NEWS b/NEWS index c6452c720040..82ee1a785501 100644 --- a/NEWS +++ b/NEWS @@ -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 diff --git a/ext/standard/syslog.c b/ext/standard/syslog.c index c5d73eb008ec..37aab54c569d 100644 --- a/ext/standard/syslog.c +++ b/ext/standard/syslog.c @@ -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; @@ -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; } 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-- + +--FILE-- + +--EXPECT-- +int(1) +array(0) { +}