bugfix: use strict MariaDB detection in install advisor#273
bugfix: use strict MariaDB detection in install advisor#273somethingwithproof wants to merge 4 commits intoCacti:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the Syslog plugin’s install advisor to correctly detect MariaDB by using a strict stripos() comparison, and adds a small regression test plus changelog entry to prevent reintroducing the issue (Fixes #270).
Changes:
- Switch MariaDB detection from loose to strict
stripos(...) === falsecomparison in the install advisor. - Add a regression test to ensure the strict comparison remains in
setup.php. - Update
CHANGELOG.mdwith the issue reference.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
setup.php |
Fixes MariaDB detection comparison used to gate Aria engine selection in the install advisor. |
tests/regression/issue270_mariadb_detection_strict_test.php |
Adds a regression check to prevent reintroduction of the loose comparison. |
CHANGELOG.md |
Documents the fix for issue #270. |
setup.php
Outdated
| @@ -963,7 +963,7 @@ function syslog_install_advisor($syslog_exists) { | |||
| $database = db_fetch_row('SHOW GLOBAL VARIABLES LIKE "version"'); | |||
There was a problem hiding this comment.
syslog_install_advisor() queries the database version using db_fetch_row(), which uses the main Cacti DB connection. When Syslog is configured to use a dedicated DB/server ($use_cacti_db = false), this can mis-detect MariaDB vs MySQL and incorrectly enable/disable the Aria engine option. Use syslog_db_fetch_row() (after syslog_connect()) so the version check runs against the Syslog DB connection.
| $database = db_fetch_row('SHOW GLOBAL VARIABLES LIKE "version"'); | |
| syslog_connect(); | |
| $database = syslog_db_fetch_row('SHOW GLOBAL VARIABLES LIKE "version"'); |
There was a problem hiding this comment.
Fixed -- using syslog_db_fetch_row() now.
setup.php
Outdated
| @@ -963,7 +963,7 @@ function syslog_install_advisor($syslog_exists) { | |||
| $database = db_fetch_row('SHOW GLOBAL VARIABLES LIKE "version"'); | |||
|
|
|||
| /* remove Aria as a storage enging if this is mysql */ | |||
There was a problem hiding this comment.
Spelling: the comment says "storage enging" but should be "storage engine".
| /* remove Aria as a storage enging if this is mysql */ | |
| /* remove Aria as a storage engine if this is mysql */ |
| $legacy = "stripos(\$database['Value'], 'mariadb') == false"; | ||
| $fixed = "stripos(\$database['Value'], 'mariadb') === false"; | ||
|
|
||
| if (strpos($setup, $legacy) !== false) { | ||
| fwrite(STDERR, "Legacy loose MariaDB stripos comparison is still present.\n"); | ||
| exit(1); | ||
| } | ||
|
|
||
| if (strpos($setup, $fixed) === false) { |
There was a problem hiding this comment.
This regression test is very brittle because it relies on exact substring matches of the source code (including spacing/quoting). A harmless reformat (or switching to syslog_db_fetch_row() while keeping the strict comparison) could make the test fail even though the behavior is correct. Consider using a regex match that ignores whitespace and accepts equivalent strict comparisons, or directly exercising the MariaDB-detection logic via a callable function if possible.
| $legacy = "stripos(\$database['Value'], 'mariadb') == false"; | |
| $fixed = "stripos(\$database['Value'], 'mariadb') === false"; | |
| if (strpos($setup, $legacy) !== false) { | |
| fwrite(STDERR, "Legacy loose MariaDB stripos comparison is still present.\n"); | |
| exit(1); | |
| } | |
| if (strpos($setup, $fixed) === false) { | |
| $legacyPattern = '/stripos\s*\(\s*\$database\s*\[\s*[\'"]Value[\'"]\s*\]\s*,\s*[\'"]mariadb[\'"]\s*\)\s*==\s*false/'; | |
| $fixedPattern = '/stripos\s*\(\s*\$database\s*\[\s*[\'"]Value[\'"]\s*\]\s*,\s*[\'"]mariadb[\'"]\s*\)\s*===\s*false/'; | |
| if (preg_match($legacyPattern, $setup)) { | |
| fwrite(STDERR, "Legacy loose MariaDB stripos comparison is still present.\n"); | |
| exit(1); | |
| } | |
| if (!preg_match($fixedPattern, $setup)) { |
There was a problem hiding this comment.
Fixed -- using preg_match() patterns now.
|
Fixed in e913ca3 -- now uses |
Fixes Cacti#270 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…dvisor db_fetch_row() uses the main Cacti DB connection; when Syslog is configured on a separate DB server, the version check could mis-detect MariaDB vs MySQL and incorrectly toggle the Aria engine option. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
strpos() exact-string matches are brittle to whitespace changes. preg_match() patterns assert operator semantics (== vs ===) without coupling to exact source formatting. Signed-off-by: Thomas Vincent <thomas@somethingwithproof.com> Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
60864db to
2ea5874
Compare
Summary
Fixes #270
Validation