Fix #16256 - Warning: error_reporting() has been disabled for security reasons on php 7.x

Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2020-07-25 19:49:07 +02:00
parent a2fb692d91
commit 0e344b6a50
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889
4 changed files with 25 additions and 4 deletions

View File

@ -779,7 +779,7 @@ class Config
$this->error_config_default_file = true;
return false;
}
$canUseErrorReporting = function_exists('error_reporting');
$canUseErrorReporting = Util::isErrorReportingAvailable();
$oldErrorReporting = null;
if ($canUseErrorReporting) {
$oldErrorReporting = error_reporting(0);
@ -837,7 +837,7 @@ class Config
* Parses the configuration file, we throw away any errors or
* output.
*/
$canUseErrorReporting = function_exists('error_reporting');
$canUseErrorReporting = Util::isErrorReportingAvailable();
$oldErrorReporting = null;
if ($canUseErrorReporting) {
$oldErrorReporting = error_reporting(0);

View File

@ -52,7 +52,7 @@ class ErrorHandler
if (! defined('TESTSUITE')) {
set_error_handler([$this, 'handleError']);
}
if (function_exists('error_reporting')) {
if (Util::isErrorReportingAvailable()) {
$this->error_reporting = error_reporting();
}
}
@ -165,7 +165,7 @@ class ErrorHandler
string $errfile,
int $errline
): void {
if (function_exists('error_reporting')) {
if (Util::isErrorReportingAvailable()) {
/**
* Check if Error Control Operator (@) was used, but still show
* user errors even in this case.

View File

@ -4997,4 +4997,24 @@ class Util
}
return '';
}
/**
* Check if error reporting is available
* @return bool
*/
public static function isErrorReportingAvailable(): bool
{
// issue #16256 - PHP 7.x does not return false for a core function
if (PHP_MAJOR_VERSION < 8) {
$disabled = ini_get('disable_functions');
if (is_string($disabled)) {
$disabled = explode(',', $disabled);
$disabled = array_map(function (string $part) {
return trim($part);
}, $disabled);
return ! in_array('error_reporting', $disabled);
}
}
return function_exists('error_reporting');
}
}

View File

@ -34,6 +34,7 @@ header('Content-Type: text/html; charset=utf-8');
require ROOT_PATH . 'libraries/vendor_config.php';
// issue #16256 - This only works with php 8.0+
if (function_exists('error_reporting')) {
error_reporting(E_ALL);
}