Skip to content

Commit

Permalink
MDEV-33160 show_status_array() calls various functions via incompatib…
Browse files Browse the repository at this point in the history
…le pointer

In commit b4ff645 the
signature of mysql_show_var_func was changed, but not all functions
of that type were adjusted.

When the server is configured with `cmake -DWITH_ASAN=ON` and
compiled with clang, runtime errors would be flagged for invoking
functions through an incompatible function pointer.

Reviewed by: Michael 'Monty' Widenius
  • Loading branch information
dr-m committed Jan 4, 2024
1 parent 54ed393 commit 613d019
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 104 deletions.
144 changes: 69 additions & 75 deletions sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7180,25 +7180,25 @@ struct my_option my_long_options[]=
MYSQL_TO_BE_IMPLEMENTED_OPTION("validate-user-plugins") // NO_EMBEDDED_ACCESS_CHECKS
};

static int show_queries(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_queries(THD *thd, SHOW_VAR *var, void *,
system_status_var *, enum_var_type)
{
var->type= SHOW_LONGLONG;
var->value= &thd->query_id;
return 0;
}


static int show_net_compression(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_net_compression(THD *thd, SHOW_VAR *var, void *,
system_status_var *, enum_var_type)
{
var->type= SHOW_MY_BOOL;
var->value= &thd->net.compress;
return 0;
}

static int show_starttime(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_starttime(THD *thd, SHOW_VAR *var, void *buff,
system_status_var *, enum_var_type)
{
var->type= SHOW_LONG;
var->value= buff;
Expand All @@ -7207,8 +7207,8 @@ static int show_starttime(THD *thd, SHOW_VAR *var, char *buff,
}

#ifdef ENABLED_PROFILING
static int show_flushstatustime(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_flushstatustime(THD *thd, SHOW_VAR *var, void *buff,
system_status_var *, enum_var_type)
{
var->type= SHOW_LONG;
var->value= buff;
Expand All @@ -7218,32 +7218,28 @@ static int show_flushstatustime(THD *thd, SHOW_VAR *var, char *buff,
#endif

#ifdef HAVE_REPLICATION
static int show_rpl_status(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_rpl_status(THD *, SHOW_VAR *var, void *, system_status_var *,
enum_var_type)
{
var->type= SHOW_CHAR;
var->value= const_cast<char*>(rpl_status_type[(int)rpl_status]);
return 0;
}

static int show_slave_running(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_slave_running(THD *thd, SHOW_VAR *var, void *buff,
system_status_var *, enum_var_type)
{
Master_info *mi= NULL;
bool UNINIT_VAR(tmp);

var->type= SHOW_MY_BOOL;
var->value= buff;

if ((mi= get_master_info(&thd->variables.default_master_connection,
Sql_condition::WARN_LEVEL_NOTE)))
if (Master_info *mi=
get_master_info(&thd->variables.default_master_connection,
Sql_condition::WARN_LEVEL_NOTE))
{
tmp= (my_bool) (mi->slave_running == MYSQL_SLAVE_RUN_READING &&
mi->rli.slave_running != MYSQL_SLAVE_NOT_RUN);
*((my_bool*) buff)=
(mi->slave_running == MYSQL_SLAVE_RUN_READING &&
mi->rli.slave_running != MYSQL_SLAVE_NOT_RUN);
mi->release();
var->type= SHOW_MY_BOOL;
var->value= buff;
}
if (mi)
*((my_bool *)buff)= tmp;
else
var->type= SHOW_UNDEF;
return 0;
Expand All @@ -7253,7 +7249,8 @@ static int show_slave_running(THD *thd, SHOW_VAR *var, char *buff,
/* How many masters this slave is connected to */


static int show_slaves_running(THD *thd, SHOW_VAR *var, char *buff)
static int show_slaves_running(THD *, SHOW_VAR *var, void *buff,
system_status_var *, enum_var_type)
{
var->type= SHOW_LONGLONG;
var->value= buff;
Expand All @@ -7264,39 +7261,35 @@ static int show_slaves_running(THD *thd, SHOW_VAR *var, char *buff)
}


static int show_slave_received_heartbeats(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_slave_received_heartbeats(THD *thd, SHOW_VAR *var, void *buff,
system_status_var *, enum_var_type)
{
Master_info *mi;

var->type= SHOW_LONGLONG;
var->value= buff;

if ((mi= get_master_info(&thd->variables.default_master_connection,
Sql_condition::WARN_LEVEL_NOTE)))
if (Master_info *mi=
get_master_info(&thd->variables.default_master_connection,
Sql_condition::WARN_LEVEL_NOTE))
{
*((longlong *)buff)= mi->received_heartbeats;
mi->release();
var->type= SHOW_LONGLONG;
var->value= buff;
}
else
var->type= SHOW_UNDEF;
return 0;
}


static int show_heartbeat_period(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_heartbeat_period(THD *thd, SHOW_VAR *var, void *buff,
system_status_var *, enum_var_type)
{
Master_info *mi;

var->type= SHOW_CHAR;
var->value= buff;

if ((mi= get_master_info(&thd->variables.default_master_connection,
Sql_condition::WARN_LEVEL_NOTE)))
if (Master_info *mi=
get_master_info(&thd->variables.default_master_connection,
Sql_condition::WARN_LEVEL_NOTE))
{
sprintf(buff, "%.3f", mi->heartbeat_period);
sprintf(static_cast<char*>(buff), "%.3f", mi->heartbeat_period);
mi->release();
var->type= SHOW_CHAR;
var->value= buff;
}
else
var->type= SHOW_UNDEF;
Expand All @@ -7306,17 +7299,17 @@ static int show_heartbeat_period(THD *thd, SHOW_VAR *var, char *buff,

#endif /* HAVE_REPLICATION */

static int show_open_tables(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_open_tables(THD *, SHOW_VAR *var, void *buff,
system_status_var *, enum_var_type)
{
var->type= SHOW_LONG;
var->value= buff;
*((long *) buff)= (long) tc_records();
return 0;
}

static int show_prepared_stmt_count(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_prepared_stmt_count(THD *, SHOW_VAR *var, void *buff,
system_status_var *, enum_var_type)
{
var->type= SHOW_LONG;
var->value= buff;
Expand All @@ -7326,8 +7319,8 @@ static int show_prepared_stmt_count(THD *thd, SHOW_VAR *var, char *buff,
return 0;
}

static int show_table_definitions(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_table_definitions(THD *, SHOW_VAR *var, void *buff,
system_status_var *, enum_var_type)
{
var->type= SHOW_LONG;
var->value= buff;
Expand All @@ -7336,8 +7329,8 @@ static int show_table_definitions(THD *thd, SHOW_VAR *var, char *buff,
}


static int show_flush_commands(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_flush_commands(THD *, SHOW_VAR *var, void *buff,
system_status_var *, enum_var_type)
{
var->type= SHOW_LONGLONG;
var->value= buff;
Expand All @@ -7356,8 +7349,8 @@ static int show_flush_commands(THD *thd, SHOW_VAR *var, char *buff,
inside an Event.
*/

static int show_ssl_get_version(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_ssl_get_version(THD *thd, SHOW_VAR *var, void *,
system_status_var *, enum_var_type)
{
var->type= SHOW_CHAR;
if( thd->vio_ok() && thd->net.vio->ssl_arg )
Expand All @@ -7367,8 +7360,8 @@ static int show_ssl_get_version(THD *thd, SHOW_VAR *var, char *buff,
return 0;
}

static int show_ssl_get_default_timeout(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_ssl_get_default_timeout(THD *thd, SHOW_VAR *var, void *buff,
system_status_var *, enum_var_type)
{
var->type= SHOW_LONG;
var->value= buff;
Expand All @@ -7379,8 +7372,8 @@ static int show_ssl_get_default_timeout(THD *thd, SHOW_VAR *var, char *buff,
return 0;
}

static int show_ssl_get_verify_mode(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_ssl_get_verify_mode(THD *thd, SHOW_VAR *var, void *buff,
system_status_var *, enum_var_type)
{
var->type= SHOW_LONG;
var->value= buff;
Expand All @@ -7395,8 +7388,8 @@ static int show_ssl_get_verify_mode(THD *thd, SHOW_VAR *var, char *buff,
return 0;
}

static int show_ssl_get_verify_depth(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_ssl_get_verify_depth(THD *thd, SHOW_VAR *var, void *buff,
system_status_var *, enum_var_type)
{
var->type= SHOW_LONG;
var->value= buff;
Expand All @@ -7408,8 +7401,8 @@ static int show_ssl_get_verify_depth(THD *thd, SHOW_VAR *var, char *buff,
return 0;
}

static int show_ssl_get_cipher(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_ssl_get_cipher(THD *thd, SHOW_VAR *var, void *buff,
system_status_var *, enum_var_type)
{
var->type= SHOW_CHAR;
if( thd->vio_ok() && thd->net.vio->ssl_arg )
Expand All @@ -7419,9 +7412,10 @@ static int show_ssl_get_cipher(THD *thd, SHOW_VAR *var, char *buff,
return 0;
}

static int show_ssl_get_cipher_list(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_ssl_get_cipher_list(THD *thd, SHOW_VAR *var, void *buf,
system_status_var *, enum_var_type)
{
char *buff= static_cast<char*>(buf);
var->type= SHOW_CHAR;
var->value= buff;
if (thd->vio_ok() && thd->net.vio->ssl_arg)
Expand Down Expand Up @@ -7506,8 +7500,8 @@ my_asn1_time_to_string(const ASN1_TIME *time, char *buf, size_t len)
*/

static int
show_ssl_get_server_not_before(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
show_ssl_get_server_not_before(THD *thd, SHOW_VAR *var, void *buff,
system_status_var *, enum_var_type)
{
var->type= SHOW_CHAR;
if(thd->vio_ok() && thd->net.vio->ssl_arg)
Expand All @@ -7516,7 +7510,7 @@ show_ssl_get_server_not_before(THD *thd, SHOW_VAR *var, char *buff,
X509 *cert= SSL_get_certificate(ssl);
const ASN1_TIME *not_before= X509_get0_notBefore(cert);

var->value= my_asn1_time_to_string(not_before, buff,
var->value= my_asn1_time_to_string(not_before, static_cast<char*>(buff),
SHOW_VAR_FUNC_BUFF_SIZE);
if (!var->value)
return 1;
Expand All @@ -7540,8 +7534,8 @@ show_ssl_get_server_not_before(THD *thd, SHOW_VAR *var, char *buff,
*/

static int
show_ssl_get_server_not_after(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
show_ssl_get_server_not_after(THD *thd, SHOW_VAR *var, void *buff,
system_status_var *, enum_var_type)
{
var->type= SHOW_CHAR;
if(thd->vio_ok() && thd->net.vio->ssl_arg)
Expand All @@ -7550,7 +7544,7 @@ show_ssl_get_server_not_after(THD *thd, SHOW_VAR *var, char *buff,
X509 *cert= SSL_get_certificate(ssl);
const ASN1_TIME *not_after= X509_get0_notAfter(cert);

var->value= my_asn1_time_to_string(not_after, buff,
var->value= my_asn1_time_to_string(not_after, static_cast<char*>(buff),
SHOW_VAR_FUNC_BUFF_SIZE);
if (!var->value)
return 1;
Expand Down Expand Up @@ -7604,7 +7598,7 @@ static int show_default_keycache(THD *thd, SHOW_VAR *var, void *buff,
}


static int show_memory_used(THD *thd, SHOW_VAR *var, char *buff,
static int show_memory_used(THD *thd, SHOW_VAR *var, void *buff,
struct system_status_var *status_var,
enum enum_var_type scope)
{
Expand Down Expand Up @@ -7660,8 +7654,8 @@ static int debug_status_func(THD *thd, SHOW_VAR *var, void *buff,
#endif

#ifdef HAVE_POOL_OF_THREADS
int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
int show_threadpool_idle_threads(THD *, SHOW_VAR *var, void *buff,
system_status_var *, enum_var_type)
{
var->type= SHOW_INT;
var->value= buff;
Expand All @@ -7670,8 +7664,8 @@ int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff,
}


static int show_threadpool_threads(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_threadpool_threads(THD *, SHOW_VAR *var, void *buff,
system_status_var *, enum_var_type)
{
var->type= SHOW_INT;
var->value= buff;
Expand Down
8 changes: 4 additions & 4 deletions sql/sql_acl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11869,8 +11869,8 @@ static my_bool count_column_grants(void *grant_table,
This must be performed under the mutex in order to make sure the
iteration does not fail.
*/
static int show_column_grants(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_column_grants(THD *thd, SHOW_VAR *var, void *buff,
system_status_var *, enum enum_var_type scope)
{
var->type= SHOW_ULONG;
var->value= buff;
Expand All @@ -11886,8 +11886,8 @@ static int show_column_grants(THD *thd, SHOW_VAR *var, char *buff,
return 0;
}

static int show_database_grants(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
static int show_database_grants(THD *thd, SHOW_VAR *var, void *buff,
system_status_var *, enum enum_var_type scope)
{
var->type= SHOW_UINT;
var->value= buff;
Expand Down
4 changes: 2 additions & 2 deletions sql/table_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1345,8 +1345,8 @@ int tdc_iterate(THD *thd, my_hash_walk_action action, void *argument,
}


int show_tc_active_instances(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
int show_tc_active_instances(THD *thd, SHOW_VAR *var, void *buff,
system_status_var *, enum enum_var_type scope)
{
var->type= SHOW_UINT;
var->value= buff;
Expand Down
4 changes: 2 additions & 2 deletions sql/table_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ extern int tdc_iterate(THD *thd, my_hash_walk_action action, void *argument,
bool no_dups= false);

extern uint tc_records(void);
int show_tc_active_instances(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope);
int show_tc_active_instances(THD *thd, SHOW_VAR *var, void *buff,
system_status_var *, enum enum_var_type scope);
extern void tc_purge(bool mark_flushed= false);
extern void tc_add_table(THD *thd, TABLE *table);
extern void tc_release_table(TABLE *table);
Expand Down
3 changes: 0 additions & 3 deletions sql/threadpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ extern int tp_get_thread_count();
/* Activate threadpool scheduler */
extern void tp_scheduler(void);

extern int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope);

enum TP_PRIORITY {
TP_PRIORITY_HIGH,
TP_PRIORITY_LOW,
Expand Down
Loading

0 comments on commit 613d019

Please sign in to comment.