From c46082a19699cac774f7a7c762688a20e9277727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 3 Oct 2017 14:54:45 +0200 Subject: [PATCH] Make advisor evaluation a bit stricter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - whitelist function names, we do not want to replace them if they exist - define missing PMA_MYSQL_INT_VERSION Fixes #13710 Signed-off-by: Michal Čihař --- ChangeLog | 1 + libraries/Advisor.php | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 429142a03b..6148e76f64 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,7 @@ phpMyAdmin - ChangeLog - issue #13669 Fixed selecting multiple rows accidentally selects the next row too - issue #13513 Fixed edit index Column alignment issue - issue #13515 Fixed rendering of add index dialog +- issue #13710 Fixed possible error in server advisor 4.7.4 (2017-08-23) - issue #13415 Remove shadow from the logo diff --git a/libraries/Advisor.php b/libraries/Advisor.php index 31e07c4bf5..c18d9a728b 100644 --- a/libraries/Advisor.php +++ b/libraries/Advisor.php @@ -134,6 +134,7 @@ class Advisor $memory = $sysinfo->memory(); $this->variables['system_memory'] = isset($memory['MemTotal']) ? $memory['MemTotal'] : 0; + $this->variables['PMA_MYSQL_INT_VERSION'] = PMA_MYSQL_INT_VERSION; // Step 2: Read and parse the list of rules $this->setParseResult(static::parseRulesFile()); @@ -401,13 +402,29 @@ class Advisor */ private function ruleExprEvaluateVariable($matches) { - if (! isset($this->variables[$matches[1]])) { - return $matches[1]; + $match = $matches[1]; + /* Numbers */ + if (is_numeric($match)) { + return $match; } - if (is_numeric($this->variables[$matches[1]])) { - return $this->variables[$matches[1]]; + /* Functions */ + $functions = array( + 'round', 'substr', 'preg_match', 'array', + 'ADVISOR_bytime', 'ADVISOR_timespanFormat', + 'ADVISOR_formatByteDown' + ); + if (in_array($match, $functions)) { + return $match; + } + /* Unknown variable */ + if (! isset($this->variables[$match])) { + return $match; + } + /* Variable value */ + if (is_numeric($this->variables[$match])) { + return $this->variables[$match]; } else { - return '\'' . addslashes($this->variables[$matches[1]]) . '\''; + return '\'' . addslashes($this->variables[$match]) . '\''; } }