Skip to content

Commit

Permalink
Extract some of MariaDB#3360 fixes to 10.5.x
Browse files Browse the repository at this point in the history
That PR uncovered countless issues on `my_snprintf` uses.
This commit backports a squashed subset of their fixes.
  • Loading branch information
ParadoxV5 committed Sep 13, 2024
1 parent b331cde commit 562f5a6
Show file tree
Hide file tree
Showing 24 changed files with 102 additions and 101 deletions.
2 changes: 1 addition & 1 deletion client/mysqldump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1739,7 +1739,7 @@ static int switch_character_set_results(MYSQL *mysql, const char *cs_name)
query_length= my_snprintf(query_buffer,
sizeof (query_buffer),
"SET SESSION character_set_results = '%s'",
(const char *) cs_name);
cs_name);

return mysql_real_query(mysql, query_buffer, (ulong)query_length);
}
Expand Down
22 changes: 11 additions & 11 deletions plugin/server_audit/server_audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ static size_t log_header(char *message, size_t message_len,
if (output_type == OUTPUT_SYSLOG)
return my_snprintf(message, message_len,
"%.*s,%.*s,%.*s,%d,%lld,%s",
(unsigned int) serverhost_len, serverhost,
(int) serverhost_len, serverhost,
username_len, username,
host_len, host,
connection_id, query_id, operation);
Expand All @@ -1408,7 +1408,7 @@ static size_t log_header(char *message, size_t message_len,
"%04d%02d%02d %02d:%02d:%02d,%.*s,%.*s,%.*s,%d,%lld,%s",
tm_time.tm_year+1900, tm_time.tm_mon+1, tm_time.tm_mday,
tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec,
serverhost_len, serverhost,
(int) serverhost_len, serverhost,
username_len, username,
host_len, host,
connection_id, query_id, operation);
Expand Down Expand Up @@ -1477,7 +1477,7 @@ static int log_connection_event(const struct mysql_event_connection *event,
event->ip, event->ip_length,
event->thread_id, 0, type);
csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize,
",%.*s,,%d", event->database.length, event->database.str, event->status);
",%.*s,,%d", (int) event->database.length, event->database.str, event->status);
message[csize]= '\n';
return write_log(message, csize + 1, 1);
}
Expand Down Expand Up @@ -1909,9 +1909,9 @@ static int log_table(const struct connection_info *cn,
event->host, SAFE_STRLEN_UI(event->host),
event->ip, SAFE_STRLEN_UI(event->ip),
event->thread_id, cn->query_id, type);
csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize,
",%.*s,%.*s,",event->database.length, event->database.str,
event->table.length, event->table.str);
csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize, ",%.*s,%.*s,",
(int) event->database.length, event->database.str,
(int) event->table.length, event->table.str);
message[csize]= '\n';
return write_log(message, csize + 1, 1);
}
Expand All @@ -1932,10 +1932,11 @@ static int log_rename(const struct connection_info *cn,
event->ip, SAFE_STRLEN_UI(event->ip),
event->thread_id, cn->query_id, "RENAME");
csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize,
",%.*s,%.*s|%.*s.%.*s,",event->database.length, event->database.str,
event->table.length, event->table.str,
event->new_database.length, event->new_database.str,
event->new_table.length, event->new_table.str);
",%.*s,%.*s|%.*s.%.*s,",
(int) event->database.length, event->database.str,
(int) event->table.length, event->table.str,
(int) event->new_database.length, event->new_database.str,
(int) event->new_table.length, event->new_table.str);
message[csize]= '\n';
return write_log(message, csize + 1, 1);
}
Expand Down Expand Up @@ -3108,4 +3109,3 @@ void __attribute__ ((constructor)) audit_plugin_so_init(void)
return;
#endif
}

2 changes: 1 addition & 1 deletion sql/item_cmpfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6105,7 +6105,7 @@ bool Regexp_processor_pcre::compile(String *pattern, bool send_error)
(PCRE2_UCHAR8 *)buff, sizeof(buff));
if (lmsg >= 0)
my_snprintf(buff+lmsg, sizeof(buff)-lmsg,
" at offset %d", pcreErrorOffset);
" at offset %zu", pcreErrorOffset);
my_error(ER_REGEXP_ERROR, MYF(0), buff);
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions sql/item_geofunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ String *Item_func_geometry_from_json::val_str(String *str)
if (code)
{
THD *thd= current_thd;
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, code,
ER_THD(thd, code));
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, code,
ER_THD(thd, code));
}
return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions sql/item_strfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4231,9 +4231,9 @@ longlong Item_func_uncompressed_length::val_int()
if (res->length() <= 4)
{
THD *thd= current_thd;
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_ZLIB_Z_DATA_ERROR,
ER_THD(thd, ER_ZLIB_Z_DATA_ERROR));
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
ER_ZLIB_Z_DATA_ERROR,
ER_THD(thd, ER_ZLIB_Z_DATA_ERROR));
null_value= 1;
return 0;
}
Expand Down Expand Up @@ -4350,7 +4350,7 @@ String *Item_func_uncompress::val_str(String *str)
if (res->length() <= 4)
{
THD *thd= current_thd;
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
ER_ZLIB_Z_DATA_ERROR,
ER_THD(thd, ER_ZLIB_Z_DATA_ERROR));
goto err;
Expand Down
4 changes: 2 additions & 2 deletions sql/log_event_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4042,7 +4042,7 @@ int Xid_apply_log_event::do_apply_event(rpl_group_info *rgi)
}
}

general_log_print(thd, COM_QUERY, get_query());
general_log_print(thd, COM_QUERY, "%s", get_query());
thd->variables.option_bits&= ~OPTION_GTID_BEGIN;
res= do_commit();
if (!res && rgi->gtid_pending)
Expand Down Expand Up @@ -7854,7 +7854,7 @@ void issue_long_find_row_warning(Log_event_type type,
"while looking up records to be processed. Consider adding a "
"primary key (or unique key) to the table to improve "
"performance.",
evt_type, table_name, (long) delta, scan_type);
evt_type, table_name, delta, scan_type);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion sql/my_decimal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int decimal_operation_results(int result, const char *value, const char *type)
value, type);
break;
case E_DEC_DIV_ZERO:
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
ER_DIVISION_BY_ZERO, ER_THD(thd, ER_DIVISION_BY_ZERO));
break;
case E_DEC_BAD_NUM:
Expand Down
2 changes: 1 addition & 1 deletion sql/slave.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7041,7 +7041,7 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len)
"the last seen GTID is %u-%u-%llu",
Log_event::get_type_str((Log_event_type) (uchar)
buf[EVENT_TYPE_OFFSET]),
mi->last_queued_gtid);
PARAM_GTID(mi->last_queued_gtid));
goto err;
}
}
Expand Down
16 changes: 7 additions & 9 deletions sql/sql_acl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12100,9 +12100,9 @@ void Sql_cmd_grant::warn_hostname_requires_resolving(THD *thd,
while ((user= it++))
{
if (opt_skip_name_resolve && hostname_requires_resolving(user->host.str))
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_WARN_HOSTNAME_WONT_WORK,
ER_THD(thd, ER_WARN_HOSTNAME_WONT_WORK));
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
ER_WARN_HOSTNAME_WONT_WORK,
ER_THD(thd, ER_WARN_HOSTNAME_WONT_WORK));
}
}

Expand Down Expand Up @@ -13280,7 +13280,7 @@ static bool secure_auth(THD *thd)
else
{
my_error(ER_NOT_SUPPORTED_AUTH_MODE, MYF(0));
general_log_print(thd, COM_CONNECT,
general_log_print(thd, COM_CONNECT, "%s",
ER_THD(thd, ER_NOT_SUPPORTED_AUTH_MODE));
}
return 1;
Expand Down Expand Up @@ -13353,7 +13353,7 @@ static bool send_plugin_request_packet(MPVIO_EXT *mpvio,
if (switch_from_short_to_long_scramble)
{
my_error(ER_NOT_SUPPORTED_AUTH_MODE, MYF(0));
general_log_print(mpvio->auth_info.thd, COM_CONNECT,
general_log_print(mpvio->auth_info.thd, COM_CONNECT, "%s",
ER_THD(mpvio->auth_info.thd, ER_NOT_SUPPORTED_AUTH_MODE));
DBUG_RETURN (1);
}
Expand Down Expand Up @@ -13443,7 +13443,7 @@ static bool find_mpvio_user(MPVIO_EXT *mpvio)
!ignore_max_password_errors(mpvio->acl_user))
{
my_error(ER_USER_IS_BLOCKED, MYF(0));
general_log_print(mpvio->auth_info.thd, COM_CONNECT,
general_log_print(mpvio->auth_info.thd, COM_CONNECT, "%s",
ER_THD(mpvio->auth_info.thd, ER_USER_IS_BLOCKED));
DBUG_RETURN(1);
}
Expand All @@ -13458,7 +13458,7 @@ static bool find_mpvio_user(MPVIO_EXT *mpvio)
DBUG_ASSERT(my_strcasecmp(system_charset_info,
mpvio->acl_user->auth->plugin.str, old_password_plugin_name.str));
my_error(ER_NOT_SUPPORTED_AUTH_MODE, MYF(0));
general_log_print(mpvio->auth_info.thd, COM_CONNECT,
general_log_print(mpvio->auth_info.thd, COM_CONNECT, "%s",
ER_THD(mpvio->auth_info.thd, ER_NOT_SUPPORTED_AUTH_MODE));
DBUG_RETURN (1);
}
Expand Down Expand Up @@ -15004,5 +15004,3 @@ extern "C" void maria_update_hostname(
*ip_mask= h.ip_mask;
#endif
}


2 changes: 1 addition & 1 deletion sql/sql_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ void set_thd_stage_info(void *thd,

#include "wsrep.h"
#include "wsrep_on.h"
#ifdef WITH_WSREP
#include <inttypes.h>
#ifdef WITH_WSREP
/* wsrep-lib */
#include "wsrep_client_service.h"
#include "wsrep_client_state.h"
Expand Down
6 changes: 2 additions & 4 deletions sql/sql_trigger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1838,10 +1838,8 @@ bool add_table_for_trigger(THD *thd,
{
if (if_exists)
{
push_warning_printf(thd,
Sql_condition::WARN_LEVEL_NOTE,
ER_TRG_DOES_NOT_EXIST,
ER_THD(thd, ER_TRG_DOES_NOT_EXIST));
push_warning(thd, Sql_condition::WARN_LEVEL_NOTE,
ER_TRG_DOES_NOT_EXIST, ER_THD(thd, ER_TRG_DOES_NOT_EXIST));

*table= NULL;

Expand Down
2 changes: 1 addition & 1 deletion sql/sql_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ class Sec6
size_t to_string(char *to, size_t nbytes) const
{
return m_usec ?
my_snprintf(to, nbytes, "%s%llu.%06lu",
my_snprintf(to, nbytes, "%s%llu.%06u",
m_neg ? "-" : "", m_sec, (uint) m_usec) :
my_snprintf(to, nbytes, "%s%llu", m_neg ? "-" : "", m_sec);
}
Expand Down
12 changes: 6 additions & 6 deletions sql/sql_yacc.yy
Original file line number Diff line number Diff line change
Expand Up @@ -2224,17 +2224,17 @@ master_def:

if (unlikely(Lex->mi.heartbeat_period > slave_net_timeout))
{
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX,
ER_THD(thd, ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX));
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX,
ER_THD(thd, ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX));
}
if (unlikely(Lex->mi.heartbeat_period < 0.001))
{
if (unlikely(Lex->mi.heartbeat_period != 0.0))
{
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN,
ER_THD(thd, ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN));
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN,
ER_THD(thd, ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN));
Lex->mi.heartbeat_period= 0.0;
}
Lex->mi.heartbeat_opt= LEX_MASTER_INFO::LEX_MI_DISABLE;
Expand Down
85 changes: 45 additions & 40 deletions sql/table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3830,50 +3830,54 @@ static void print_long_unique_table(TABLE *table)
" fields->offset,field->null_bit, field->null_pos and key_info ... \n"
"\nPrinting Table keyinfo\n");
str.append(buff, strlen(buff));
my_snprintf(buff, sizeof(buff), "\ntable->s->reclength %d\n"
"table->s->fields %d\n",
my_snprintf(buff, sizeof(buff), "\ntable->s->reclength %lu\n"
"table->s->fields %u\n",
table->s->reclength, table->s->fields);
str.append(buff, strlen(buff));
for (uint i= 0; i < table->s->keys; i++)
{
key_info_table= table->key_info + i;
key_info_share= table->s->key_info + i;
my_snprintf(buff, sizeof(buff), "\ntable->key_info[%d] user_defined_key_parts = %d\n"
"table->key_info[%d] algorithm == HA_KEY_ALG_LONG_HASH = %d\n"
"table->key_info[%d] flags & HA_NOSAME = %d\n",
i, key_info_table->user_defined_key_parts,
i, key_info_table->algorithm == HA_KEY_ALG_LONG_HASH,
i, key_info_table->flags & HA_NOSAME);
my_snprintf(buff, sizeof(buff),
"\ntable->key_info[%u] user_defined_key_parts = %u\n"
"table->key_info[%u] algorithm == HA_KEY_ALG_LONG_HASH = %d\n"
"table->key_info[%u] flags & HA_NOSAME = %lu\n",
i, key_info_table->user_defined_key_parts,
i, key_info_table->algorithm == HA_KEY_ALG_LONG_HASH,
i, key_info_table->flags & HA_NOSAME);
str.append(buff, strlen(buff));
my_snprintf(buff, sizeof(buff), "\ntable->s->key_info[%d] user_defined_key_parts = %d\n"
"table->s->key_info[%d] algorithm == HA_KEY_ALG_LONG_HASH = %d\n"
"table->s->key_info[%d] flags & HA_NOSAME = %d\n",
i, key_info_share->user_defined_key_parts,
i, key_info_share->algorithm == HA_KEY_ALG_LONG_HASH,
i, key_info_share->flags & HA_NOSAME);
my_snprintf(buff, sizeof(buff),
"\ntable->s->key_info[%u] user_defined_key_parts = %u\n"
"table->s->key_info[%u] algorithm == HA_KEY_ALG_LONG_HASH = %d\n"
"table->s->key_info[%u] flags & HA_NOSAME = %lu\n",
i, key_info_share->user_defined_key_parts,
i, key_info_share->algorithm == HA_KEY_ALG_LONG_HASH,
i, key_info_share->flags & HA_NOSAME);
str.append(buff, strlen(buff));
key_part = key_info_table->key_part;
my_snprintf(buff, sizeof(buff), "\nPrinting table->key_info[%d].key_part[0] info\n"
"key_part->offset = %d\n"
"key_part->field_name = %s\n"
"key_part->length = %d\n"
"key_part->null_bit = %d\n"
"key_part->null_offset = %d\n",
i, key_part->offset, key_part->field->field_name.str, key_part->length,
key_part->null_bit, key_part->null_offset);
my_snprintf(buff, sizeof(buff),
"\nPrinting table->key_info[%u].key_part[0] info\n"
"key_part->offset = %u\n"
"key_part->field_name = %s\n"
"key_part->length = %u\n"
"key_part->null_bit = %u\n"
"key_part->null_offset = %u\n",
i, key_part->offset, key_part->field->field_name.str, key_part->length,
key_part->null_bit, key_part->null_offset);
str.append(buff, strlen(buff));

for (uint j= 0; j < key_info_share->user_defined_key_parts; j++)
{
key_part= key_info_share->key_part + j;
my_snprintf(buff, sizeof(buff), "\nPrinting share->key_info[%d].key_part[%d] info\n"
"key_part->offset = %d\n"
"key_part->field_name = %s\n"
"key_part->length = %d\n"
"key_part->null_bit = %d\n"
"key_part->null_offset = %d\n",
i,j,key_part->offset, key_part->field->field_name.str, key_part->length,
key_part->null_bit, key_part->null_offset);
my_snprintf(buff, sizeof(buff),
"\nPrinting share->key_info[%u].key_part[%u] info\n"
"key_part->offset = %u\n"
"key_part->field_name = %s\n"
"key_part->length = %u\n"
"key_part->null_bit = %u\n"
"key_part->null_offset = %u\n",
i, j, key_part->offset, key_part->field->field_name.str,
key_part->length, key_part->null_bit, key_part->null_offset);
str.append(buff, strlen(buff));
}
}
Expand All @@ -3882,16 +3886,17 @@ static void print_long_unique_table(TABLE *table)
for(uint i= 0; i < table->s->fields; i++)
{
field= table->field[i];
my_snprintf(buff, sizeof(buff), "\ntable->field[%d]->field_name %s\n"
"table->field[%d]->offset = %d\n"
"table->field[%d]->field_length = %d\n"
"table->field[%d]->null_pos wrt to record 0 = %d\n"
"table->field[%d]->null_bit_pos = %d\n",
i, field->field_name.str,
i, field->ptr- table->record[0],
i, field->pack_length(),
i, field->null_bit ? field->null_ptr - table->record[0] : -1,
i, field->null_bit);
my_snprintf(buff, sizeof(buff),
"\ntable->field[%u]->field_name %s\n"
"table->field[%u]->offset = %" PRIdPTR "\n" // `%td` not available
"table->field[%u]->field_length = %d\n"
"table->field[%u]->null_pos wrt to record 0 = %" PRIdPTR "\n"
"table->field[%u]->null_bit_pos = %d\n",
i, field->field_name.str,
i, field->ptr- table->record[0],
i, field->pack_length(),
i, field->null_bit ? field->null_ptr - table->record[0] : -1,
i, field->null_bit);
str.append(buff, strlen(buff));
}
(*error_handler_hook)(1, str.ptr(), ME_NOTE);
Expand Down
2 changes: 1 addition & 1 deletion sql/wsrep_var.cc
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ bool wsrep_max_ws_size_update(sys_var *self, THD *thd, enum_var_type)
{
char max_ws_size_opt[128];
my_snprintf(max_ws_size_opt, sizeof(max_ws_size_opt),
"repl.max_ws_size=%d", wsrep_max_ws_size);
"repl.max_ws_size=%lu", wsrep_max_ws_size);
enum wsrep::provider::status ret= Wsrep_server_state::instance().provider().options(max_ws_size_opt);
if (ret)
{
Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11329,7 +11329,7 @@ create_table_info_t::check_table_options()
push_warning_printf(
m_thd, Sql_condition::WARN_LEVEL_WARN,
HA_WRONG_CREATE_OPTION,
"InnoDB: invalid PAGE_COMPRESSION_LEVEL = %lu."
"InnoDB: invalid PAGE_COMPRESSION_LEVEL = %llu."
" Valid values are [1, 2, 3, 4, 5, 6, 7, 8, 9]",
options->page_compression_level);
return "PAGE_COMPRESSION_LEVEL";
Expand Down Expand Up @@ -21527,7 +21527,7 @@ ib_foreign_warn(trx_t* trx, /*!< in: trx */
if (trx && trx->mysql_thd) {
THD* thd = (THD*)trx->mysql_thd;

push_warning_printf(
push_warning(
thd, Sql_condition::WARN_LEVEL_WARN,
uint(convert_error_code_to_mysql(error, 0, thd)), buf);
}
Expand Down
Loading

0 comments on commit 562f5a6

Please sign in to comment.