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
v3.0-lint
Rene Cannao 2 months ago
parent 5ccb715e57
commit bf9030ecb7

@ -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";

@ -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);

Loading…
Cancel
Save