Skip to content

Commit ffdf25a

Browse files
Mikhail Galaninbukka
Mikhail Galanin
authored andcommittedJul 18, 2022
Add "error_log_mode" setting
1 parent 7db9c2a commit ffdf25a

File tree

5 files changed

+54
-2
lines changed

5 files changed

+54
-2
lines changed
 

‎NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ PHP NEWS
1515
http_build_query(), strstr(), Reflection*::__toString(). (Arnaud)
1616
. Fixed bug GH-8995 (WeakMap object reference offset causing TypeError).
1717
(Tobias Bachert)
18+
. Added error_log_mode ini setting. (Mikhail Galanin)
1819

1920
- COM:
2021
. Fixed bug GH-8750 (Can not create VT_ERROR variant type). (cmb)

‎UPGRADING

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ PHP 8.2 UPGRADE NOTES
7676
RFC: https://wiki.php.net/rfc/true-type
7777
. Added support for Disjoint Normal Form (DNF) types.
7878
RFC: https://wiki.php.net/rfc/dnf_types
79+
. Added error_log_mode ini setting that allows setting of permissions for
80+
error log file.
7981

8082

8183
- Curl:

‎main/main.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,8 @@ PHP_INI_BEGIN()
712712
STD_PHP_INI_ENTRY("internal_encoding", NULL, PHP_INI_ALL, OnUpdateInternalEncoding, internal_encoding, php_core_globals, core_globals)
713713
STD_PHP_INI_ENTRY("input_encoding", NULL, PHP_INI_ALL, OnUpdateInputEncoding, input_encoding, php_core_globals, core_globals)
714714
STD_PHP_INI_ENTRY("output_encoding", NULL, PHP_INI_ALL, OnUpdateOutputEncoding, output_encoding, php_core_globals, core_globals)
715-
STD_PHP_INI_ENTRY("error_log", NULL, PHP_INI_ALL, OnUpdateErrorLog, error_log, php_core_globals, core_globals)
715+
STD_PHP_INI_ENTRY("error_log", NULL, PHP_INI_ALL, OnUpdateErrorLog, error_log, php_core_globals, core_globals)
716+
STD_PHP_INI_ENTRY("error_log_mode", "0644", PHP_INI_ALL, OnUpdateLong, error_log_mode, php_core_globals, core_globals)
716717
STD_PHP_INI_ENTRY("extension_dir", PHP_EXTENSION_DIR, PHP_INI_SYSTEM, OnUpdateStringUnempty, extension_dir, php_core_globals, core_globals)
717718
STD_PHP_INI_ENTRY("sys_temp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, sys_temp_dir, php_core_globals, core_globals)
718719
STD_PHP_INI_ENTRY("include_path", PHP_INCLUDE_PATH, PHP_INI_ALL, OnUpdateStringUnempty, include_path, php_core_globals, core_globals)
@@ -807,14 +808,23 @@ PHPAPI ZEND_COLD void php_log_err_with_severity(const char *log_message, int sys
807808

808809
/* Try to use the specified logging location. */
809810
if (PG(error_log) != NULL) {
811+
int error_log_mode;
812+
810813
#ifdef HAVE_SYSLOG_H
811814
if (!strcmp(PG(error_log), "syslog")) {
812815
php_syslog(syslog_type_int, "%s", log_message);
813816
PG(in_error_log) = 0;
814817
return;
815818
}
816819
#endif
817-
fd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND | O_WRONLY, 0644);
820+
821+
error_log_mode = 0644;
822+
823+
if (PG(error_log_mode) > 0 && PG(error_log_mode) <= 0777) {
824+
error_log_mode = PG(error_log_mode);
825+
}
826+
827+
fd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND | O_WRONLY, error_log_mode);
818828
if (fd != -1) {
819829
char *tmp;
820830
size_t len;

‎main/php_globals.h

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ struct _php_core_globals {
165165
char *syslog_ident;
166166
bool have_called_openlog;
167167
zend_long syslog_filter;
168+
zend_long error_log_mode;
168169
};
169170

170171

‎tests/basic/errorlog_permission.phpt

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
Check permissions for created errorlog file
3+
--SKIPIF--
4+
<?php
5+
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
6+
die("skip this test on windows");
7+
}
8+
?>
9+
--INI--
10+
error_log=error_permissions_test.log
11+
error_log_mode=0600
12+
--FILE--
13+
<?php
14+
15+
const LOG_FILENAME='error_permissions_test.log';
16+
17+
try {
18+
if (file_exists(LOG_FILENAME)) {
19+
unlink(LOG_FILENAME);
20+
}
21+
$oldMask = umask(0000);
22+
23+
error_log("hello world");
24+
25+
assert(file_exists(LOG_FILENAME));
26+
27+
printf("got permissions=%o\n", fileperms(LOG_FILENAME) & 0777);
28+
printf("errorlog contents\n%s", file_get_contents(LOG_FILENAME));
29+
30+
umask($oldMask);
31+
} finally {
32+
unlink(LOG_FILENAME);
33+
}
34+
?>
35+
--EXPECTF--
36+
got permissions=600
37+
errorlog contents
38+
[%d-%s-%d %d:%d:%d %s] hello world

0 commit comments

Comments
 (0)
Please sign in to comment.