From c12ba18600d997a7b058ff97da77c51e9d3ddebb Mon Sep 17 00:00:00 2001 From: Tim van Dijen <tvdijen@gmail.com> Date: Tue, 9 Mar 2021 14:42:07 +0100 Subject: [PATCH] Remove any non-printable characters from the logging.processname --- lib/SimpleSAML/Logger/ErrorLogLoggingHandler.php | 3 ++- lib/SimpleSAML/Logger/FileLoggingHandler.php | 4 +++- lib/SimpleSAML/Logger/StandardErrorLoggingHandler.php | 3 ++- lib/SimpleSAML/Logger/SyslogLoggingHandler.php | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/SimpleSAML/Logger/ErrorLogLoggingHandler.php b/lib/SimpleSAML/Logger/ErrorLogLoggingHandler.php index bfd0f2abb..e5c0cefa5 100644 --- a/lib/SimpleSAML/Logger/ErrorLogLoggingHandler.php +++ b/lib/SimpleSAML/Logger/ErrorLogLoggingHandler.php @@ -45,7 +45,8 @@ class ErrorLogLoggingHandler implements LoggingHandlerInterface */ public function __construct(Configuration $config) { - $this->processname = $config->getString('logging.processname', 'SimpleSAMLphp'); + // Remove any non-printable characters before storing + $this->processname = preg_replace('/[\x00-\x1F\x7F\xA0]/u', '', $config->getString('logging.processname', 'SimpleSAMLphp')); } diff --git a/lib/SimpleSAML/Logger/FileLoggingHandler.php b/lib/SimpleSAML/Logger/FileLoggingHandler.php index 641a5f235..ca2c87bcd 100644 --- a/lib/SimpleSAML/Logger/FileLoggingHandler.php +++ b/lib/SimpleSAML/Logger/FileLoggingHandler.php @@ -55,7 +55,9 @@ class FileLoggingHandler implements LoggingHandlerInterface // get the metadata handler option from the configuration $this->logFile = $config->getPathValue('loggingdir', 'log/') . $config->getString('logging.logfile', 'simplesamlphp.log'); - $this->processname = $config->getString('logging.processname', 'SimpleSAMLphp'); + + // Remove any non-printable characters before storing + $this->processname = preg_replace('/[\x00-\x1F\x7F\xA0]/u', '', $config->getString('logging.processname', 'SimpleSAMLphp')); if (@file_exists($this->logFile)) { if (!@is_writeable($this->logFile)) { diff --git a/lib/SimpleSAML/Logger/StandardErrorLoggingHandler.php b/lib/SimpleSAML/Logger/StandardErrorLoggingHandler.php index c6860a2a2..e2a8f93a0 100644 --- a/lib/SimpleSAML/Logger/StandardErrorLoggingHandler.php +++ b/lib/SimpleSAML/Logger/StandardErrorLoggingHandler.php @@ -22,7 +22,8 @@ class StandardErrorLoggingHandler extends FileLoggingHandler */ public function __construct(Configuration $config) { - $this->processname = $config->getString('logging.processname', 'SimpleSAMLphp'); + // Remove any non-printable characters before storing + $this->processname = preg_replace('/[\x00-\x1F\x7F\xA0]/u', '', $config->getString('logging.processname', 'SimpleSAMLphp')); $this->logFile = 'php://stderr'; } } diff --git a/lib/SimpleSAML/Logger/SyslogLoggingHandler.php b/lib/SimpleSAML/Logger/SyslogLoggingHandler.php index 14309cac0..7cf2fc6d0 100644 --- a/lib/SimpleSAML/Logger/SyslogLoggingHandler.php +++ b/lib/SimpleSAML/Logger/SyslogLoggingHandler.php @@ -29,7 +29,8 @@ class SyslogLoggingHandler implements LoggingHandlerInterface { $facility = $config->getInteger('logging.facility', defined('LOG_LOCAL5') ? constant('LOG_LOCAL5') : LOG_USER); - $processname = $config->getString('logging.processname', 'SimpleSAMLphp'); + // Remove any non-printable characters before storing + $processname = preg_replace('/[\x00-\x1F\x7F\xA0]/u', '', $config->getString('logging.processname', 'SimpleSAMLphp')); // Setting facility to LOG_USER (only valid in Windows), enable log level rewrite on windows systems if (Utils\System::getOS() === Utils\System::WINDOWS) { -- GitLab