sourcemod
sourcemod copied to clipboard
Calling database in AskPluginLoad2 segfaults if dependencies fail to load
Help us help you
- [x] I have checked that my issue doesn't exist yet.
- [x] I have tried my absolute best to reduce the problem-space and have provided the absolute smallest test-case possible.
- [x] I can always reproduce the issue with the provided description below.
Environment
- Operating System version: Linux / Ubuntu 22.04 LTS
- Game/AppID (with version if applicable): TF2 / 232250
- Current SourceMod version: 1.11
- Current SourceMod snapshot: 1.11.0.6906
- Current Metamod: Source snapshot: 1.11.0-dev+1148
- [x] I have updated SourceMod to the latest version and it still happens.
- [x] I have updated SourceMod to the latest snapshot and it still happens.
- [x] I have updated SourceMM to the latest snapshot and it still happens.
Description
Performing a database query while inside AskPluginLoad2
can segfault with double free or corruption (!prev)
if a plugin dependency (in this case, GeoIP) fails to load.
This crash was found when debugging the Player Analytics plugin that queries the database like in the snippet below. This happened after updating the server's SourceMod binaries to a new version that switched to the new GeoLite2 .mmdb database format but was missing a working GeoLite2-City.mmdb
file, which caused the GeoIP extension to fail to load. A similar but different crash was observed if the snippet below ran with the GeoIP extension removed entirely.
Problematic Code
#include <sourcemod>
#include <geoip>
public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int iErrMax) {
Handle hDB = SQL_Connect("mysql_db_goes_here", true, sError, iErrMax);
SQL_TQuery(hDB, SQLTCallback_TableCreated, "CREATE TABLE IF NOT EXISTS `test` (id INT)");
}
public SQLTCallback_TableCreated(Handle hOwner, Handle hHndl, const char[] sError, any aData) {
}
Crash Dumps
https://crash.limetech.org/sxkx5wbngjsy https://crash.limetech.org/cqysbu2bizuf