Skip to content

Commit cf2d49d

Browse files
ParadoxV5grooverdan
authored andcommitted
Extract some of #3360 fixes to 10.5.x
That PR uncovered countless issues on `my_snprintf` uses. This commit backports a squashed subset of their fixes.
1 parent b414eca commit cf2d49d

24 files changed

+102
-101
lines changed

client/mysqldump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,7 @@ static int switch_character_set_results(MYSQL *mysql, const char *cs_name)
17391739
query_length= my_snprintf(query_buffer,
17401740
sizeof (query_buffer),
17411741
"SET SESSION character_set_results = '%s'",
1742-
(const char *) cs_name);
1742+
cs_name);
17431743

17441744
return mysql_real_query(mysql, query_buffer, (ulong)query_length);
17451745
}

plugin/server_audit/server_audit.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ static size_t log_header(char *message, size_t message_len,
13981398
if (output_type == OUTPUT_SYSLOG)
13991399
return my_snprintf(message, message_len,
14001400
"%.*s,%.*s,%.*s,%d,%lld,%s",
1401-
(unsigned int) serverhost_len, serverhost,
1401+
(int) serverhost_len, serverhost,
14021402
username_len, username,
14031403
host_len, host,
14041404
connection_id, query_id, operation);
@@ -1408,7 +1408,7 @@ static size_t log_header(char *message, size_t message_len,
14081408
"%04d%02d%02d %02d:%02d:%02d,%.*s,%.*s,%.*s,%d,%lld,%s",
14091409
tm_time.tm_year+1900, tm_time.tm_mon+1, tm_time.tm_mday,
14101410
tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec,
1411-
serverhost_len, serverhost,
1411+
(int) serverhost_len, serverhost,
14121412
username_len, username,
14131413
host_len, host,
14141414
connection_id, query_id, operation);
@@ -1477,7 +1477,7 @@ static int log_connection_event(const struct mysql_event_connection *event,
14771477
event->ip, event->ip_length,
14781478
event->thread_id, 0, type);
14791479
csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize,
1480-
",%.*s,,%d", event->database.length, event->database.str, event->status);
1480+
",%.*s,,%d", (int) event->database.length, event->database.str, event->status);
14811481
message[csize]= '\n';
14821482
return write_log(message, csize + 1, 1);
14831483
}
@@ -1909,9 +1909,9 @@ static int log_table(const struct connection_info *cn,
19091909
event->host, SAFE_STRLEN_UI(event->host),
19101910
event->ip, SAFE_STRLEN_UI(event->ip),
19111911
event->thread_id, cn->query_id, type);
1912-
csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize,
1913-
",%.*s,%.*s,",event->database.length, event->database.str,
1914-
event->table.length, event->table.str);
1912+
csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize, ",%.*s,%.*s,",
1913+
(int) event->database.length, event->database.str,
1914+
(int) event->table.length, event->table.str);
19151915
message[csize]= '\n';
19161916
return write_log(message, csize + 1, 1);
19171917
}
@@ -1932,10 +1932,11 @@ static int log_rename(const struct connection_info *cn,
19321932
event->ip, SAFE_STRLEN_UI(event->ip),
19331933
event->thread_id, cn->query_id, "RENAME");
19341934
csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize,
1935-
",%.*s,%.*s|%.*s.%.*s,",event->database.length, event->database.str,
1936-
event->table.length, event->table.str,
1937-
event->new_database.length, event->new_database.str,
1938-
event->new_table.length, event->new_table.str);
1935+
",%.*s,%.*s|%.*s.%.*s,",
1936+
(int) event->database.length, event->database.str,
1937+
(int) event->table.length, event->table.str,
1938+
(int) event->new_database.length, event->new_database.str,
1939+
(int) event->new_table.length, event->new_table.str);
19391940
message[csize]= '\n';
19401941
return write_log(message, csize + 1, 1);
19411942
}
@@ -3108,4 +3109,3 @@ void __attribute__ ((constructor)) audit_plugin_so_init(void)
31083109
return;
31093110
#endif
31103111
}
3111-

sql/item_cmpfunc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6105,7 +6105,7 @@ bool Regexp_processor_pcre::compile(String *pattern, bool send_error)
61056105
(PCRE2_UCHAR8 *)buff, sizeof(buff));
61066106
if (lmsg >= 0)
61076107
my_snprintf(buff+lmsg, sizeof(buff)-lmsg,
6108-
" at offset %d", pcreErrorOffset);
6108+
" at offset %zu", pcreErrorOffset);
61096109
my_error(ER_REGEXP_ERROR, MYF(0), buff);
61106110
}
61116111
return true;

sql/item_geofunc.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ String *Item_func_geometry_from_json::val_str(String *str)
185185
if (code)
186186
{
187187
THD *thd= current_thd;
188-
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, code,
189-
ER_THD(thd, code));
188+
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, code,
189+
ER_THD(thd, code));
190190
}
191191
return 0;
192192
}

sql/item_strfunc.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4231,9 +4231,9 @@ longlong Item_func_uncompressed_length::val_int()
42314231
if (res->length() <= 4)
42324232
{
42334233
THD *thd= current_thd;
4234-
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
4235-
ER_ZLIB_Z_DATA_ERROR,
4236-
ER_THD(thd, ER_ZLIB_Z_DATA_ERROR));
4234+
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
4235+
ER_ZLIB_Z_DATA_ERROR,
4236+
ER_THD(thd, ER_ZLIB_Z_DATA_ERROR));
42374237
null_value= 1;
42384238
return 0;
42394239
}
@@ -4350,7 +4350,7 @@ String *Item_func_uncompress::val_str(String *str)
43504350
if (res->length() <= 4)
43514351
{
43524352
THD *thd= current_thd;
4353-
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
4353+
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
43544354
ER_ZLIB_Z_DATA_ERROR,
43554355
ER_THD(thd, ER_ZLIB_Z_DATA_ERROR));
43564356
goto err;

sql/log_event_server.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4036,7 +4036,7 @@ int Xid_apply_log_event::do_apply_event(rpl_group_info *rgi)
40364036
}
40374037
}
40384038

4039-
general_log_print(thd, COM_QUERY, get_query());
4039+
general_log_print(thd, COM_QUERY, "%s", get_query());
40404040
thd->variables.option_bits&= ~OPTION_GTID_BEGIN;
40414041
res= do_commit();
40424042
if (!res && rgi->gtid_pending)
@@ -7845,7 +7845,7 @@ void issue_long_find_row_warning(Log_event_type type,
78457845
"while looking up records to be processed. Consider adding a "
78467846
"primary key (or unique key) to the table to improve "
78477847
"performance.",
7848-
evt_type, table_name, (long) delta, scan_type);
7848+
evt_type, table_name, delta, scan_type);
78497849
}
78507850
}
78517851
}

sql/my_decimal.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int decimal_operation_results(int result, const char *value, const char *type)
5959
value, type);
6060
break;
6161
case E_DEC_DIV_ZERO:
62-
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
62+
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
6363
ER_DIVISION_BY_ZERO, ER_THD(thd, ER_DIVISION_BY_ZERO));
6464
break;
6565
case E_DEC_BAD_NUM:

sql/slave.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7059,7 +7059,7 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len)
70597059
"the last seen GTID is %u-%u-%llu",
70607060
Log_event::get_type_str((Log_event_type) (uchar)
70617061
buf[EVENT_TYPE_OFFSET]),
7062-
mi->last_queued_gtid);
7062+
PARAM_GTID(mi->last_queued_gtid));
70637063
goto err;
70647064
}
70657065
}

sql/sql_acl.cc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12115,9 +12115,9 @@ void Sql_cmd_grant::warn_hostname_requires_resolving(THD *thd,
1211512115
while ((user= it++))
1211612116
{
1211712117
if (opt_skip_name_resolve && hostname_requires_resolving(user->host.str))
12118-
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
12119-
ER_WARN_HOSTNAME_WONT_WORK,
12120-
ER_THD(thd, ER_WARN_HOSTNAME_WONT_WORK));
12118+
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
12119+
ER_WARN_HOSTNAME_WONT_WORK,
12120+
ER_THD(thd, ER_WARN_HOSTNAME_WONT_WORK));
1212112121
}
1212212122
}
1212312123

@@ -13295,7 +13295,7 @@ static bool secure_auth(THD *thd)
1329513295
else
1329613296
{
1329713297
my_error(ER_NOT_SUPPORTED_AUTH_MODE, MYF(0));
13298-
general_log_print(thd, COM_CONNECT,
13298+
general_log_print(thd, COM_CONNECT, "%s",
1329913299
ER_THD(thd, ER_NOT_SUPPORTED_AUTH_MODE));
1330013300
}
1330113301
return 1;
@@ -13368,7 +13368,7 @@ static bool send_plugin_request_packet(MPVIO_EXT *mpvio,
1336813368
if (switch_from_short_to_long_scramble)
1336913369
{
1337013370
my_error(ER_NOT_SUPPORTED_AUTH_MODE, MYF(0));
13371-
general_log_print(mpvio->auth_info.thd, COM_CONNECT,
13371+
general_log_print(mpvio->auth_info.thd, COM_CONNECT, "%s",
1337213372
ER_THD(mpvio->auth_info.thd, ER_NOT_SUPPORTED_AUTH_MODE));
1337313373
DBUG_RETURN (1);
1337413374
}
@@ -13458,7 +13458,7 @@ static bool find_mpvio_user(MPVIO_EXT *mpvio)
1345813458
!ignore_max_password_errors(mpvio->acl_user))
1345913459
{
1346013460
my_error(ER_USER_IS_BLOCKED, MYF(0));
13461-
general_log_print(mpvio->auth_info.thd, COM_CONNECT,
13461+
general_log_print(mpvio->auth_info.thd, COM_CONNECT, "%s",
1346213462
ER_THD(mpvio->auth_info.thd, ER_USER_IS_BLOCKED));
1346313463
DBUG_RETURN(1);
1346413464
}
@@ -13473,7 +13473,7 @@ static bool find_mpvio_user(MPVIO_EXT *mpvio)
1347313473
DBUG_ASSERT(my_strcasecmp(system_charset_info,
1347413474
mpvio->acl_user->auth->plugin.str, old_password_plugin_name.str));
1347513475
my_error(ER_NOT_SUPPORTED_AUTH_MODE, MYF(0));
13476-
general_log_print(mpvio->auth_info.thd, COM_CONNECT,
13476+
general_log_print(mpvio->auth_info.thd, COM_CONNECT, "%s",
1347713477
ER_THD(mpvio->auth_info.thd, ER_NOT_SUPPORTED_AUTH_MODE));
1347813478
DBUG_RETURN (1);
1347913479
}
@@ -15019,5 +15019,3 @@ extern "C" void maria_update_hostname(
1501915019
*ip_mask= h.ip_mask;
1502015020
#endif
1502115021
}
15022-
15023-

sql/sql_class.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ void set_thd_stage_info(void *thd,
6767

6868
#include "wsrep.h"
6969
#include "wsrep_on.h"
70-
#ifdef WITH_WSREP
7170
#include <inttypes.h>
71+
#ifdef WITH_WSREP
7272
/* wsrep-lib */
7373
#include "wsrep_client_service.h"
7474
#include "wsrep_client_state.h"

0 commit comments

Comments
 (0)