Skip to content

bugfix: use strict MariaDB detection in install advisor#273

Open
somethingwithproof wants to merge 4 commits intoCacti:developfrom
somethingwithproof:bug/mariadb-detection-strict
Open

bugfix: use strict MariaDB detection in install advisor#273
somethingwithproof wants to merge 4 commits intoCacti:developfrom
somethingwithproof:bug/mariadb-detection-strict

Conversation

@somethingwithproof
Copy link

Summary

Fixes #270

Validation

  • php -l setup.php
  • php -l tests/regression/issue270_mariadb_detection_strict_test.php
  • php tests/regression/issue270_mariadb_detection_strict_test.php

Copilot AI review requested due to automatic review settings March 7, 2026 02:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(...) === false comparison in the install advisor.
  • Add a regression test to ensure the strict comparison remains in setup.php.
  • Update CHANGELOG.md with 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"');
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
$database = db_fetch_row('SHOW GLOBAL VARIABLES LIKE "version"');
syslog_connect();
$database = syslog_db_fetch_row('SHOW GLOBAL VARIABLES LIKE "version"');

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 */
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling: the comment says "storage enging" but should be "storage engine".

Suggested change
/* remove Aria as a storage enging if this is mysql */
/* remove Aria as a storage engine if this is mysql */

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines +10 to +18
$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) {
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
$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)) {

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed -- using preg_match() patterns now.

@somethingwithproof
Copy link
Author

Fixed in e913ca3 -- now uses syslog_db_fetch_row() so the version check runs against the Syslog DB connection. The spelling was already correct in this branch.

somethingwithproof and others added 4 commits March 7, 2026 05:32
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>
@somethingwithproof somethingwithproof force-pushed the bug/mariadb-detection-strict branch from 60864db to 2ea5874 Compare March 7, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: MariaDB detection uses loose stripos comparison in upgrade advisor

2 participants