Skip to content

Fix crash in dbi_connect: initialize DatabaseInfo::charset - #1170

Merged
dvander merged 1 commit into
alliedmodders:masterfrom
Geesu:fix/dbi-connect-charset
Nov 11, 2026
Merged

dvander merged 1 commit into
alliedmodders:masterfrom
Geesu:fix/dbi-connect-charset

Conversation

@Geesu

@Geesu Geesu commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Problem

Plugins using the legacy DBI natives crash the server as soon as dbi_connect() successfully logs in to MySQL.

dbi_connect() in modules/mysqlx/oldcompat_sql.cpp builds a DatabaseInfo on the stack and sets host, user, pass, database and port, but never charset. The DatabaseInfo constructor only initializes max_timeout, so charset holds stack garbage. After a successful login, MysqlDriver::_Connect() does:

if (info->charset && *info->charset)

which dereferences that garbage pointer:

segfault at 7f ... in mysql_amxx_i386.so
SourceMod::MysqlDriver::_Connect(SourceMod::DatabaseInfo*, int*, char*, unsigned int, bool)

A failed login (e.g. a wrong password) returns before this point, so the crash only shows up once the credentials are correct. SQLX callers (SQL_MakeDbTuple / SQL_Connect, threaded queries) set charset explicitly and aren't affected.

Fix

Initialize charset to nullptr in the DatabaseInfo constructor, which covers every caller. The sqlite copy of ISQLDriver.h has the same struct, so it gets the same change to keep the two in sync.

Testing

Linux: HLDS build 10211, Metamod 1.21.1-am, AMX Mod X 1.10.0.5467 (module rebuilt from that revision with this change), MariaDB 10.6.

  • War3XP 2.6.4 (DBI natives): with the stock module the server segfaulted on every map start (9/9). With the patched module it connects, runs its CREATE TABLE and keeps the connection, with no crashes.
  • War3FT 3.0.1 (SQLX) on the patched module: still connects and runs normally.

@dvander

dvander commented Nov 11, 2026

Copy link
Copy Markdown
Member

Thanks!

@dvander
dvander merged commit 844eebd into alliedmodders:master Nov 11, 2026
3 checks passed
Geesu added a commit to wc3mods/war3ft that referenced this pull request Nov 11, 2026
…fresh clone

5488 fixes the mysql module's dbi_connect crash (alliedmodders/amxmodx#1170). The build
script also creates build/ and build_tmp/ itself, so it works on a fresh clone.
Geesu added a commit to wc3mods/war3x that referenced this pull request Nov 11, 2026
…fresh clone

5488 fixes the mysql module's dbi_connect crash (alliedmodders/amxmodx#1170). The build
script also creates build/ and build_tmp/ itself, so it works on a fresh clone.
Geesu added a commit to wc3mods/war3xp that referenced this pull request Nov 11, 2026
…fresh clone

5488 fixes the mysql module's dbi_connect crash (alliedmodders/amxmodx#1170). The build
script also creates build/ and build_tmp/ itself, so it works on a fresh clone.
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.

2 participants