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 Aug 28, 2024
1 parent e7bb9b7 commit ab0e105
Show file tree
Hide file tree
Showing 19 changed files with 90 additions and 89 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
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 @@ -7852,7 +7852,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
}


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
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
87 changes: 46 additions & 41 deletions sql/table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3829,68 +3829,73 @@ 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));
}
}
my_snprintf(buff, sizeof(buff), "\nPrinting table->fields\n");
strcpy(buff, "\nPrinting table->fields\n");
str.append(buff, strlen(buff));
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
8 changes: 4 additions & 4 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 @@ -21469,7 +21469,7 @@ ib_push_warning(
buf[MAX_BUF_SIZE - 1] = 0;
vsnprintf(buf, MAX_BUF_SIZE - 1, format, args);

push_warning_printf(
push_warning(
thd, Sql_condition::WARN_LEVEL_WARN,
uint(convert_error_code_to_mysql(error, 0, thd)), buf);
my_free(buf);
Expand Down Expand Up @@ -21501,7 +21501,7 @@ ib_push_warning(
buf[MAX_BUF_SIZE - 1] = 0;
vsnprintf(buf, MAX_BUF_SIZE - 1, format, args);

push_warning_printf(
push_warning(
thd, Sql_condition::WARN_LEVEL_WARN,
uint(convert_error_code_to_mysql(error, 0, thd)), buf);
my_free(buf);
Expand Down Expand Up @@ -21547,7 +21547,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
4 changes: 2 additions & 2 deletions storage/innobase/trx/trx0undo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ trx_undo_mem_create_at_db_start(trx_rseg_t *rseg, ulint id, uint32_t page_no)
+ block->frame);
const trx_id_t trx_id= mach_read_from_8(undo_header + TRX_UNDO_TRX_ID);
if (trx_id >> 48) {
sql_print_error("InnoDB: corrupted TRX_ID %llx", trx_id);
sql_print_error("InnoDB: corrupted TRX_ID %" PRIx64, trx_id);
goto corrupted;
}
/* We will increment rseg->needs_purge, like trx_undo_reuse_cached()
Expand Down Expand Up @@ -913,7 +913,7 @@ trx_undo_mem_create_at_db_start(trx_rseg_t *rseg, ulint id, uint32_t page_no)
read_trx_no:
trx_no = mach_read_from_8(TRX_UNDO_TRX_NO + undo_header);
if (trx_no >> 48) {
sql_print_error("InnoDB: corrupted TRX_NO %llx",
sql_print_error("InnoDB: corrupted TRX_NO %" PRIx64,
trx_no);
goto corrupted;
}
Expand Down
2 changes: 1 addition & 1 deletion storage/maria/s3_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ my_bool s3_rename_object(ms3_st *s3_client, const char *aws_bucket,
if (!(errmsg= ms3_server_error(s3_client)))
errmsg= ms3_error(error);

my_printf_error(EE_READ, "Got error from move_object(%s -> %s): %d %",
my_printf_error(EE_READ, "Got error from move_object(%s -> %s): %d %s",
error_flags,
from_name, to_name, error, errmsg);
}
Expand Down
2 changes: 1 addition & 1 deletion storage/mroonga/lib/mrn_multiple_column_key_codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ namespace mrn {
"data: <%.*s>",
normalized_length,
UINT_MAX16,
field->field_name,
field->field_name.str,
blob_data_length, blob_data);
memcpy(grn_key, normalized, blob_data_length);
new_blob_data_length = blob_data_length;
Expand Down
4 changes: 2 additions & 2 deletions storage/myisam/ha_myisam.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ int ha_myisam::assign_to_keycache(THD* thd, HA_CHECK_OPT *check_opt)
param->db_name= table->s->db.str;
param->table_name= table->s->table_name.str;
param->testflag= 0;
mi_check_print_error(param, errmsg);
mi_check_print_error(param, "%s", errmsg);
}
DBUG_RETURN(error);
}
Expand Down Expand Up @@ -1543,7 +1543,7 @@ int ha_myisam::preload_keys(THD* thd, HA_CHECK_OPT *check_opt)
param->db_name= table->s->db.str;
param->table_name= table->s->table_name.str;
param->testflag= 0;
mi_check_print_error(param, errmsg);
mi_check_print_error(param, "%s", errmsg);
DBUG_RETURN(error);
}
}
Expand Down
Loading

0 comments on commit ab0e105

Please sign in to comment.