Skip to content

Add "error_log_mode" setting #7901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 12 additions & 2 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,8 @@ PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("internal_encoding", NULL, PHP_INI_ALL, OnUpdateInternalEncoding, internal_encoding, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("input_encoding", NULL, PHP_INI_ALL, OnUpdateInputEncoding, input_encoding, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("output_encoding", NULL, PHP_INI_ALL, OnUpdateOutputEncoding, output_encoding, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("error_log", NULL, PHP_INI_ALL, OnUpdateErrorLog, error_log, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("error_log", NULL, PHP_INI_ALL, OnUpdateErrorLog, error_log, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("error_log_mode", "0644", PHP_INI_ALL, OnUpdateLong, error_log_mode, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("extension_dir", PHP_EXTENSION_DIR, PHP_INI_SYSTEM, OnUpdateStringUnempty, extension_dir, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("sys_temp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, sys_temp_dir, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("include_path", PHP_INCLUDE_PATH, PHP_INI_ALL, OnUpdateStringUnempty, include_path, php_core_globals, core_globals)
Expand Down Expand Up @@ -807,14 +808,23 @@ PHPAPI ZEND_COLD void php_log_err_with_severity(const char *log_message, int sys

/* Try to use the specified logging location. */
if (PG(error_log) != NULL) {
int error_log_mode;

#ifdef HAVE_SYSLOG_H
if (!strcmp(PG(error_log), "syslog")) {
php_syslog(syslog_type_int, "%s", log_message);
PG(in_error_log) = 0;
return;
}
#endif
fd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND | O_WRONLY, 0644);

error_log_mode = 0644;

if (PG(error_log_mode) > 0 && PG(error_log_mode) <= 0777) {
error_log_mode = PG(error_log_mode);
}

fd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND | O_WRONLY, error_log_mode);
if (fd != -1) {
char *tmp;
size_t len;
Expand Down
1 change: 1 addition & 0 deletions main/php_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ struct _php_core_globals {
char *syslog_ident;
bool have_called_openlog;
zend_long syslog_filter;
zend_long error_log_mode;
};


Expand Down
38 changes: 38 additions & 0 deletions tests/basic/errorlog_permission.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--TEST--
Check permissions for created errorlog file
--SKIPIF--
<?php
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
die("skip this test on windows");
}
?>
--INI--
error_log=error_permissions_test.log
error_log_mode=0600
--FILE--
<?php

const LOG_FILENAME='error_permissions_test.log';

try {
if (file_exists(LOG_FILENAME)) {
unlink(LOG_FILENAME);
}
$oldMask = umask(0000);

error_log("hello world");

assert(file_exists(LOG_FILENAME));

printf("got permissions=%o\n", fileperms(LOG_FILENAME) & 0777);
printf("errorlog contents\n%s", file_get_contents(LOG_FILENAME));

umask($oldMask);
} finally {
unlink(LOG_FILENAME);
}
?>
--EXPECTF--
got permissions=600
errorlog contents
[%d-%s-%d %d:%d:%d %s] hello world