From bf9030ecb76863351b2bcb60d7a110d2c1c55831 Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Fri, 10 Apr 2026 04:36:10 +0000 Subject: [PATCH] fix: remaining cppcheck printf and null pointer issues - Fix wrongPrintfScanfArgNum: remove extra args in 4 sprintf calls - Fix nullPointer: add GloMTH check, add null checks for strdup args - All high-risk cppcheck warnings now resolved --- lib/MySQL_HostGroups_Manager.cpp | 4 ++-- lib/MySQL_Session.cpp | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/MySQL_HostGroups_Manager.cpp b/lib/MySQL_HostGroups_Manager.cpp index 83c584409..2ce710b6f 100644 --- a/lib/MySQL_HostGroups_Manager.cpp +++ b/lib/MySQL_HostGroups_Manager.cpp @@ -2335,7 +2335,7 @@ void MySQL_HostGroups_Manager::push_MyConn_to_pool(MySQL_Connection *c, bool _lo } // If the largest query length exceeds the threshold, destroy the connection - if (c->largest_query_length > (unsigned int)GloMTH->variables.threshold_query_length) { + if (GloMTH && c->largest_query_length > (unsigned int)GloMTH->variables.threshold_query_length) { proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 7, "Destroying MySQL_Connection %p, server %s:%d with status %d . largest_query_length = %lu\n", c, mysrvc->address, mysrvc->port, (int)mysrvc->get_status(), c->largest_query_length); delete c; goto __exit_push_MyConn_to_pool; @@ -4995,7 +4995,7 @@ void MySQL_HostGroups_Manager::update_galera_set_read_only(char *_hostname, int //free(query); q=(char *)"DELETE FROM mysql_servers_incoming WHERE hostname='%s' AND port=%d AND hostgroup_id in (%d, %d, %d)"; //query=(char *)malloc(strlen(q)+strlen(_hostname)+64); - sprintf(query,q,_hostname,_port, info->offline_hostgroup, info->backup_writer_hostgroup, info->writer_hostgroup, info->writer_hostgroup); + sprintf(query,q,_hostname,_port, info->offline_hostgroup, info->backup_writer_hostgroup, info->writer_hostgroup); mydb->execute(query); //free(query); q=(char *)"UPDATE mysql_servers_incoming SET status=0 WHERE hostname='%s' AND port=%d AND hostgroup_id=%d"; diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 38883df1e..f1a1b11ff 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -202,9 +202,9 @@ KillArgs::KillArgs(char* u, char* p, char* h, unsigned int P, unsigned int _hid, } KillArgs::KillArgs(char* u, char* p, char* h, unsigned int P, unsigned int _hid, unsigned long i, int kt, int _use_ssl, MySQL_Thread *_mt, char *ip) { - username=strdup(u); - password=strdup(p); - hostname=strdup(h); + username=u ? strdup(u) : nullptr; + password=p ? strdup(p) : nullptr; + hostname=h ? strdup(h) : nullptr; ip_addr = NULL; if (ip) ip_addr = strdup(ip); @@ -3349,7 +3349,7 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C string nqn = string((char *)CurrentQuery.QueryPointer,l); char *err_msg = (char *)"Session trying to reach HG %d while locked on HG %d . Rejecting query: %s"; char *buf = (char *)malloc(strlen(err_msg)+strlen(nqn.c_str())+strlen(end)+64); - sprintf(buf, err_msg, current_hostgroup, locked_on_hostgroup, nqn.c_str(), end); + sprintf(buf, err_msg, current_hostgroup, locked_on_hostgroup, nqn.c_str()); client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,client_myds->pkt_sid+1,9005,(char *)"HY000",buf, true); thread->status_variables.stvar[st_var_hostgroup_locked_queries]++; RequestEnd(NULL, 9005, buf); @@ -3522,7 +3522,7 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C string nqn = string((char *)CurrentQuery.stmt_info->query,l); char *err_msg = (char *)"Session trying to reach HG %d while locked on HG %d . Rejecting query: %s"; char *buf = (char *)malloc(strlen(err_msg)+strlen(nqn.c_str())+strlen(end)+64); - sprintf(buf, err_msg, current_hostgroup, locked_on_hostgroup, nqn.c_str(), end); + sprintf(buf, err_msg, current_hostgroup, locked_on_hostgroup, nqn.c_str()); client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,client_myds->pkt_sid+1,9005,(char *)"HY000",buf, true); thread->status_variables.stvar[st_var_hostgroup_locked_queries]++; RequestEnd(NULL, 9005, buf); @@ -5394,7 +5394,7 @@ __get_pkts_from_client: string nqn = string((char *)CurrentQuery.QueryPointer,l); char *err_msg = (char *)"Session trying to reach HG %d while locked on HG %d . Rejecting query: %s"; char *buf = (char *)malloc(strlen(err_msg)+strlen(nqn.c_str())+strlen(end)+64); - sprintf(buf, err_msg, current_hostgroup, locked_on_hostgroup, nqn.c_str(), end); +sprintf(buf, err_msg, current_hostgroup, locked_on_hostgroup, nqn.c_str()); client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,client_myds->pkt_sid+1,9005,(char *)"HY000",buf, true); thread->status_variables.stvar[st_var_hostgroup_locked_queries]++; RequestEnd(NULL, 9005, buf);