From d46b50344d6ae03551eb404ab8e95f4f880343d3 Mon Sep 17 00:00:00 2001 From: DBX12 Date: Tue, 17 Oct 2017 22:43:48 +0200 Subject: [PATCH] Prevent recursive calls to MySQL::query --- classes/MySQL.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/classes/MySQL.php b/classes/MySQL.php index abce5d6..04b06ff 100644 --- a/classes/MySQL.php +++ b/classes/MySQL.php @@ -13,6 +13,13 @@ class MySQL { private $Instance=false; public $queryCount = 0; + + private $reconnectCount = 0; + + /** + * How many times should Nimda attempt to reconnect to the MySQL server + */ + const MAX_RECONNECT_COUNT = 5; function __construct($host, $user, $password, $db, $port=3306) { @@ -38,14 +45,19 @@ public function query($sql, $mode='assoc') { if(false === $Result = $this->Instance->query($sql)) { if($this->Instance->error == 'MySQL server has gone away') { - $this->connect(); + if ($this->reconnectCount >= self::MAX_RECONNECT_COUNT) { + trigger_error("Failed to reach MySQL server after {$this->reconnectCount} times, giving up.", E_USER_WARNING); + return false; + } + $this->connect(); + $this->reconnectCount++; return $this->query($sql); } else { trigger_error("MySQL Error: ".$this->Instance->error."\nSQL: ".$sql."\n", E_USER_WARNING); return false; } } - + $this->reconnectCount = 0; preg_match('/^\s*(\w+)/', strtoupper($sql), $arr); switch($arr[1]) {