From b740cb2afd370072c8ade3788b8f82292fab3771 Mon Sep 17 00:00:00 2001 From: acognet Date: Wed, 12 May 2021 08:15:29 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B02540=20-=20prevent=20the=20mysql=20passw?= =?UTF-8?q?ord=20to=20appear=20on=20misconfigured=20servers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/cmdbsource.class.inc.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/cmdbsource.class.inc.php b/core/cmdbsource.class.inc.php index 285b42ed8..f52c6a69b 100644 --- a/core/cmdbsource.class.inc.php +++ b/core/cmdbsource.class.inc.php @@ -39,6 +39,7 @@ class MySQLException extends CoreException */ public function __construct($sIssue, $aContext, $oException = null, $oMysqli = null) { + if ($oException != null) { $aContext['mysql_errno'] = $oException->getCode(); @@ -58,6 +59,11 @@ class MySQLException extends CoreException $aContext['mysql_error'] = CMDBSource::GetError(); } parent::__construct($sIssue, $aContext); + //if is connection error, don't log the default message with password in + if (mysqli_connect_errno()) { + error_log($this->message); + error_reporting(0); + } } } @@ -262,7 +268,7 @@ class CMDBSource } catch(mysqli_sql_exception $e) { - throw new MySQLException('Could not connect to the DB server', array('host' => $sServer, 'user' => $sUser), $e); + throw new MySQLException('Could not connect to the DB server', array('host' => $sServer, 'user' => $sUser),$e); } if ($bTlsEnabled