Page MenuHomeIn-Portal Phabricator

D232.id749.diff
No OneTemporary

File Metadata

Created
Wed, Feb 12, 6:47 AM

D232.id749.diff

Index: branches/5.2.x/core/kernel/utility/debugger.php
===================================================================
--- branches/5.2.x/core/kernel/utility/debugger.php
+++ branches/5.2.x/core/kernel/utility/debugger.php
@@ -1881,6 +1881,9 @@
$this->_fatalErrorHash = $this->_getErrorHash($errfile, $errline);
$this->appendTrace(4);
}
+ elseif ( !kLogger::isErrorOriginAllowed($errfile) ) {
+ return;
+ }
$this->expandError($errstr, $errfile, $errline);
Index: branches/5.2.x/core/kernel/utility/logger.php
===================================================================
--- branches/5.2.x/core/kernel/utility/logger.php
+++ branches/5.2.x/core/kernel/utility/logger.php
@@ -734,15 +734,29 @@
/**
* Writes prepared log to database or disk, when database isn't available
*
- * @param int $storage_medium
- * @return bool|int
- * @access public
- * @throws InvalidArgumentException
+ * @param integer $storage_medium Storage medium.
+ * @param boolean $check_origin Check error origin.
+ *
+ * @return integer|boolean
+ * @throws InvalidArgumentException When unknown storage medium is given.
*/
- public function write($storage_medium = self::LS_AUTOMATIC)
+ public function write($storage_medium = self::LS_AUTOMATIC, $check_origin = false)
{
- if ( !$this->_logRecord || $this->_logRecord['LogLevel'] > $this->_maxLogLevel || $this->_state == self::STATE_DISABLED ) {
- // nothing to save OR less detailed logging requested OR disabled
+ if ( $check_origin && isset($this->_logRecord['LogSourceFilename']) ) {
+ $origin_allowed = self::isErrorOriginAllowed($this->_logRecord['LogSourceFilename']);
+ }
+ else {
+ $origin_allowed = true;
+ }
+
+ if ( !$this->_logRecord
+ || $this->_logRecord['LogLevel'] > $this->_maxLogLevel
+ || !$origin_allowed
+ || $this->_state == self::STATE_DISABLED
+ ) {
+ // Nothing to save OR less detailed logging requested OR origin not allowed OR disabled.
+ $this->_logRecord = array();
+
return false;
}
@@ -1057,6 +1071,49 @@
}
/**
+ * Determines if error should be logged based on it's origin.
+ *
+ * @param string $file File.
+ *
+ * @return boolean
+ */
+ public static function isErrorOriginAllowed($file)
+ {
+ static $error_origin_regexp;
+
+ // Lazy detect error origins, because they're not available at construction time.
+ if ( !$error_origin_regexp ) {
+ $error_origins = array();
+ $application = kApplication::Instance();
+
+ foreach ( $application->ModuleInfo as $module_info ) {
+ $error_origins[] = preg_quote(rtrim($module_info['Path'], '/'), '/');
+ }
+
+ $error_origins = array_unique($error_origins);
+ $error_origin_regexp = '/^' . preg_quote(FULL_PATH, '/') . '\/(' . implode('|', $error_origins) . ')\//';
+ }
+
+ // Allow dynamically generated code.
+ if ( strpos($file, 'eval()\'d code') !== false ) {
+ return true;
+ }
+
+ // Allow known modules.
+ if ( preg_match('/^' . preg_quote(MODULES_PATH, '/') . '\//', $file) ) {
+ return preg_match($error_origin_regexp, $file) == 1;
+ }
+
+ // Don't allow Vendors.
+ if ( preg_match('/^' . preg_quote(FULL_PATH, '/') . '\/vendor\//', $file) ) {
+ return false;
+ }
+
+ // Allow everything else within main folder.
+ return preg_match('/^' . preg_quote(FULL_PATH, '/') . '\//', $file) == 1;
+ }
+
+ /**
* Parses database error message into error number, error message and sql that caused that error
*
* @static
@@ -1165,6 +1222,13 @@
$this->_handlers[] = $handler;
}
+ /**
+ * Returns `true`, when no other error handlers should process this error.
+ *
+ * @param integer $errno Error code.
+ *
+ * @return boolean
+ */
protected function _handleFatalError($errno)
{
$debug_mode = defined('DEBUG_MODE') && DEBUG_MODE;
@@ -1182,7 +1246,7 @@
}
}
- return null;
+ return false;
}
/**
@@ -1304,12 +1368,12 @@
$log = $this->_logger->prepare()->addError($errno, $errstr, $errfile, $errline);
if ( $this->_handleFatalError($errno) ) {
- $log->write();
+ $log->write(kLogger::LS_AUTOMATIC, !$this->_isFatalError($errno));
return true;
}
- $log->write();
+ $log->write(kLogger::LS_AUTOMATIC, !$this->_isFatalError($errno));
$res = false;

Event Timeline