From afe87bf69354c87506fa7544e4d0945046a5b303 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 11 May 2024 11:36:29 +0100 Subject: [PATCH] Ensure we are connected to MySQL before trying to escape data. --- modules/extra/m_mysql.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/extra/m_mysql.cpp b/modules/extra/m_mysql.cpp index 5a2b7a5b0..85b18f151 100644 --- a/modules/extra/m_mysql.cpp +++ b/modules/extra/m_mysql.cpp @@ -339,9 +339,14 @@ Result MySQLService::RunQuery(const Query &query) { this->Lock.Lock(); - Anope::string real_query = this->BuildQuery(query); + if (!this->CheckConnection()) + { + this->Lock.Unlock(); + return MySQLResult(query, query.query, mysql_error(this->sql)); + } - if (this->CheckConnection() && !mysql_real_query(this->sql, real_query.c_str(), real_query.length())) + Anope::string real_query = this->BuildQuery(query); + if (!mysql_real_query(this->sql, real_query.c_str(), real_query.length())) { MYSQL_RES *res = mysql_store_result(this->sql); unsigned int id = mysql_insert_id(this->sql);