Skip to content
/ server Public
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 33 additions & 27 deletions client/mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1446,14 +1446,20 @@ int main(int argc,char *argv[])
strlen(home) + strlen("/.mariadb_history")+2, MYF(MY_WME));
if (histfile)
{
sprintf(histfile,"%s/.mariadb_history", home);
snprintf(histfile,
strlen(home) + strlen("/.mariadb_history") + 2,
"%s/.mariadb_history", home);
if (my_access(histfile, F_OK))
{
/* no .mariadb_history, look for historical name and use if present */
sprintf(histfile,"%s/.mysql_history", home);
snprintf(histfile,
strlen(home) + strlen("/.mariadb_history") + 2,
"%s/.mysql_history", home);
/* and go back to original if not found */
if (my_access(histfile, F_OK))
sprintf(histfile,"%s/.mariadb_history", home);
snprintf(histfile,
strlen(home) + strlen("/.mariadb_history") + 2,
"%s/.mariadb_history", home);
}
char link_name[FN_REFLEN];
if (my_readlink(link_name, histfile, 0) == 0 &&
Expand Down Expand Up @@ -1481,14 +1487,14 @@ int main(int argc,char *argv[])
fprintf(stderr, "Couldn't allocate memory for temp histfile!\n");
exit(1);
}
sprintf(histfile_tmp, "%s.TMP", histfile);
snprintf(histfile_tmp, strlen(histfile) + 5, "%s.TMP", histfile);
}
}

#endif

sprintf(buff, "%s",
"Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n");
snprintf(buff, sizeof(buff), "%s",
"Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n");
put_info(buff,INFO_INFO);
status.exit_status= read_and_execute(!status.batch);
if (opt_outfile)
Expand Down Expand Up @@ -1658,9 +1664,9 @@ bool kill_query(const char *reason)
interrupted_query= 2;

/* kill_buffer is always big enough because max length of %lu is 15 */
sprintf(kill_buffer, "KILL %s%lu",
(interrupted_query == 1) ? "QUERY " : "",
mysql_thread_id(&mysql));
snprintf(kill_buffer, sizeof(kill_buffer), "KILL %s%lu",
(interrupted_query == 1) ? "QUERY " : "",
mysql_thread_id(&mysql));
if (verbose)
tee_fprintf(stdout, "%s -- sending \"%s\" to server ...\n", reason,
kill_buffer);
Expand Down Expand Up @@ -2722,7 +2728,7 @@ static bool add_line(String &buffer, char *line, size_t line_length,
}
else
{
sprintf(buff,"Unknown command '\\%c'.",inchar);
snprintf(buff, sizeof(buff), "Unknown command '\\%c'.",inchar);
if (put_info(buff,INFO_ERROR) > 0)
DBUG_RETURN(1);
*out++='\\';
Expand Down Expand Up @@ -3251,7 +3257,7 @@ You can turn off this feature to get a quicker startup with -A\n\n");
j=0;
while ((sql_field=mysql_fetch_field(fields)))
{
sprintf(buf,"%.64s.%.64s",table_row[0],sql_field->name);
snprintf(buf, sizeof(buf), "%.64s.%.64s",table_row[0],sql_field->name);
field_names[i][j] = strdup_root(&hash_mem_root,buf);
add_word(&ht,field_names[i][j]);
field_names[i][num_fields+j] = strdup_root(&hash_mem_root,
Expand Down Expand Up @@ -3731,9 +3737,9 @@ static int com_go(String *buffer, char *)
print_tab_data(result);
else
print_table_data(result);
sprintf(buff,"%ld %s in set",
(long) mysql_num_rows(result),
(long) mysql_num_rows(result) == 1 ? "row" : "rows");
snprintf(buff, sizeof(buff), "%ld %s in set",
(long) mysql_num_rows(result),
(long) mysql_num_rows(result) == 1 ? "row" : "rows");
end_pager();
if (mysql_errno(&mysql))
{
Expand All @@ -3746,9 +3752,9 @@ static int com_go(String *buffer, char *)
else if (mysql_affected_rows(&mysql) == ~(ulonglong) 0)
strmov(buff,"Query OK");
else
sprintf(buff,"Query OK, %ld %s affected",
(long) mysql_affected_rows(&mysql),
(long) mysql_affected_rows(&mysql) == 1 ? "row" : "rows");
snprintf(buff, sizeof(buff), "Query OK, %ld %s affected",
(long) mysql_affected_rows(&mysql),
(long) mysql_affected_rows(&mysql) == 1 ? "row" : "rows");

pos=strend(buff);
if ((warnings= mysql_warning_count(&mysql)))
Expand Down Expand Up @@ -3926,7 +3932,7 @@ static char *fieldflags2str(uint f) {
ff2s_check_flag(ON_UPDATE_NOW);
#undef ff2s_check_flag
if (f)
sprintf(s, " unknows=0x%04x", f);
snprintf(s, sizeof(buf) - (size_t)(s - buf), " unknows=0x%04x", f);
return buf;
}

Expand Down Expand Up @@ -4668,7 +4674,7 @@ com_edit(String *buffer,char *)
if ((error= system(buff)))
{
char errmsg[100];
sprintf(errmsg, "Command '%.40s' failed", buff);
snprintf(errmsg, sizeof(errmsg), "Command '%.40s' failed", buff);
put_info(errmsg, INFO_ERROR, 0, NullS);
goto err;
}
Expand Down Expand Up @@ -4814,10 +4820,10 @@ static int com_connect(String *buffer, char *line)

if (connected)
{
sprintf(buff,"Connection id: %lu",mysql_thread_id(&mysql));
snprintf(buff, sizeof(buff), "Connection id: %lu",mysql_thread_id(&mysql));
put_info(buff,INFO_INFO);
sprintf(buff,"Current database: %.128s\n",
current_db ? current_db : "*** NONE ***");
snprintf(buff, sizeof(buff), "Current database: %.128s\n",
current_db ? current_db : "*** NONE ***");
put_info(buff,INFO_INFO);
}
return error;
Expand Down Expand Up @@ -5168,9 +5174,9 @@ sql_real_connect(char *host,char *database,char *user,char *password,
if (safe_updates)
{
char init_command[100];
sprintf(init_command,
"SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%lu,MAX_JOIN_SIZE=%lu",
select_limit,max_join_size);
snprintf(init_command, sizeof(init_command),
"SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%lu,MAX_JOIN_SIZE=%lu",
select_limit,max_join_size);
mysql_options(&mysql, MYSQL_INIT_COMMAND, init_command);
}
if (!strcmp(default_charset,MYSQL_AUTODETECT_CHARSET_NAME))
Expand Down Expand Up @@ -5608,9 +5614,9 @@ static void nice_time(double sec, char *buff, bool part_second)
buff=strmov(buff," min ");
}
if (part_second)
sprintf(buff,"%.3f sec",sec);
snprintf(buff, 32, "%.3f sec",sec);
else
sprintf(buff,"%d sec",(int) sec);
snprintf(buff, 32, "%d sec",(int) sec);
}


Expand Down
54 changes: 27 additions & 27 deletions client/mysqlbinlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1327,29 +1327,29 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev,
}

memset(tmp_sql, 0, sizeof(tmp_sql));
sprintf(tmp_sql, " "
"SELECT Group_concat(cols) "
"FROM (SELECT 'op_type char(1)' cols "
" UNION ALL "
" SELECT Concat('`', column_name, '_old` ', column_type, ' ', "
" IF(character_set_name IS NOT NULL, "
" Concat('character set ', character_set_name, ' '), ' '), "
" IF(collation_name IS NOT NULL, "
" Concat('collate ', collation_name, ' '), ' ')) cols "
" FROM information_schema.columns "
" WHERE table_schema = '%s' "
" AND table_name = '%s' "
" UNION ALL "
" SELECT Concat('`', column_name, '_new` ', column_type, ' ', "
" IF(character_set_name IS NOT NULL, "
" Concat('character set ', character_set_name, ' '), ' '), "
" IF(collation_name IS NOT NULL, "
" Concat('collate ', collation_name, ' '), ' ')) cols "
" FROM information_schema.columns "
" WHERE table_schema = '%s' "
" AND table_name = '%s') tmp;",
map->get_db_name(), map->get_table_name(),
map->get_db_name(), map->get_table_name());
snprintf(tmp_sql, sizeof(tmp_sql), " "
"SELECT Group_concat(cols) "
"FROM (SELECT 'op_type char(1)' cols "
" UNION ALL "
" SELECT Concat('`', column_name, '_old` ', column_type, ' ', "
" IF(character_set_name IS NOT NULL, "
" Concat('character set ', character_set_name, ' '), ' '), "
" IF(collation_name IS NOT NULL, "
" Concat('collate ', collation_name, ' '), ' ')) cols "
" FROM information_schema.columns "
" WHERE table_schema = '%s' "
" AND table_name = '%s' "
" UNION ALL "
" SELECT Concat('`', column_name, '_new` ', column_type, ' ', "
" IF(character_set_name IS NOT NULL, "
" Concat('character set ', character_set_name, ' '), ' '), "
" IF(collation_name IS NOT NULL, "
" Concat('collate ', collation_name, ' '), ' ')) cols "
" FROM information_schema.columns "
" WHERE table_schema = '%s' "
" AND table_name = '%s') tmp;",
map->get_db_name(), map->get_table_name(),
map->get_db_name(), map->get_table_name());

if (mysql_query(conn, tmp_sql))
{
Expand All @@ -1374,12 +1374,12 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev,
else
{
memset(tmp_sql, 0, sizeof(tmp_sql));
sprintf(tmp_sql, "__%s", map->get_table_name());
snprintf(tmp_sql, sizeof(tmp_sql), "__%s", map->get_table_name());
ev->set_flashback_review_tablename(tmp_sql);
}
memset(tmp_sql, 0, sizeof(tmp_sql));
tmp_sql_offset= sprintf(tmp_sql, "CREATE TABLE IF NOT EXISTS");
tmp_sql_offset+= sprintf(tmp_sql + tmp_sql_offset, " `%s`.`%s` (%s) %s",
tmp_sql_offset= snprintf(tmp_sql, sizeof(tmp_sql), "CREATE TABLE IF NOT EXISTS");
tmp_sql_offset+= snprintf(tmp_sql + tmp_sql_offset, sizeof(tmp_sql) - tmp_sql_offset, " `%s`.`%s` (%s) %s",
ev->get_flashback_review_dbname(),
ev->get_flashback_review_tablename(),
row[0],
Expand All @@ -1403,7 +1403,7 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev,
else
{
memset(tmp_str, 0, sizeof(tmp_str));
sprintf(tmp_str, "__%s", map->get_table_name());
snprintf(tmp_str, sizeof(tmp_str), "__%s", map->get_table_name());
ev->set_flashback_review_tablename(tmp_str);
}
}
Expand Down
6 changes: 3 additions & 3 deletions client/mysqlcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -984,8 +984,8 @@ static int handle_request_for_tables(char *tables, size_t length,
DBUG_ASSERT(strlen(op)+strlen(tables)+strlen(options)+8+1 <= query_size);

/* No backticks here as we added them before */
query_length= sprintf(query, "%s%s%s %s", op,
tab_view, tables, options);
query_length= snprintf(query, query_size, "%s%s%s %s", op,
tab_view, tables, options);
table_name= tables;
}
else
Expand Down Expand Up @@ -1013,7 +1013,7 @@ static int handle_request_for_tables(char *tables, size_t length,
print_result();
if (opt_flush_tables)
{
query_length= sprintf(query, "FLUSH TABLES %s", table_name);
query_length= snprintf(query, query_size, "FLUSH TABLES %s", table_name);
if (mysql_real_query(sock, query, (ulong)query_length))
{
DBerror(sock, query);
Expand Down
13 changes: 7 additions & 6 deletions client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2921,7 +2921,7 @@ VAR* var_get(const char *var_name, const char **var_name_end, my_bool raw,

if (!raw && v->int_dirty)
{
sprintf(v->str_val, "%d", v->int_val);
snprintf(v->str_val, v->alloced_len, "%d", v->int_val);
v->int_dirty= false;
v->str_val_len = strlen(v->str_val);
}
Expand Down Expand Up @@ -2983,7 +2983,7 @@ void var_set(const char *var_name, const char *var_name_end,
{
if (v->int_dirty)
{
sprintf(v->str_val, "%d", v->int_val);
snprintf(v->str_val, v->alloced_len, "%d", v->int_val);
v->int_dirty=false;
v->str_val_len= strlen(v->str_val);
}
Expand Down Expand Up @@ -5289,9 +5289,10 @@ void do_sync_with_master2(struct st_command *command, long offset,
if (!master_pos.file[0])
die("Calling 'sync_with_master' without calling 'save_master_pos'");

sprintf(query_buf, "select master_pos_wait('%s', %ld, %d, '%s')",
master_pos.file, master_pos.pos + offset, timeout,
connection_name);
snprintf(query_buf, sizeof(query_buf),
"select master_pos_wait('%s', %ld, %d, '%s')",
master_pos.file, master_pos.pos + offset, timeout,
connection_name);

if (mysql_query(mysql, query_buf))
die("failed in '%s': %d: %s", query_buf, mysql_errno(mysql),
Expand Down Expand Up @@ -10935,7 +10936,7 @@ void append_info(DYNAMIC_STRING *ds, ulonglong affected_rows,
const char *info)
{
char buf[40], buff2[21];
size_t len= sprintf(buf,"affected rows: %s\n", llstr(affected_rows, buff2));
size_t len= snprintf(buf, sizeof(buf), "affected rows: %s\n", llstr(affected_rows, buff2));
dynstr_append_mem(ds, buf, len);
if (info)
{
Expand Down
2 changes: 1 addition & 1 deletion extra/mariabackup/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static inline int vasprintf(char **strp, const char *fmt, va_list args)
{
return -1;
}
vsprintf(*strp, fmt, args);
vsnprintf(*strp, len + 1, fmt, args);
return len;
}

Expand Down
12 changes: 7 additions & 5 deletions extra/mariabackup/xbcloud.cc
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ static char *hex_md5(const unsigned char *hash, char *out)
int i;

for (i = 0, p = out; i < hash_len; i++, p+=2) {
sprintf(p, "%02x", hash[i]);
snprintf(p, 3, "%02x", hash[i]);
}

return out;
Expand Down Expand Up @@ -548,6 +548,7 @@ swift_temp_auth(const char *auth_url, swift_auth_info *info)
CURLcode res;
long http_code;
char *hdr_buf = NULL;
size_t hdr_buf_size = 0;
struct curl_slist *slist = NULL;

if (opt_swift_user == NULL) {
Expand All @@ -564,18 +565,19 @@ swift_temp_auth(const char *auth_url, swift_auth_info *info)

if (curl != NULL) {

hdr_buf = (char *)(calloc(14 + max(strlen(opt_swift_user),
strlen(opt_swift_key)), 1));
hdr_buf_size = 14 + max(strlen(opt_swift_user),
strlen(opt_swift_key));
hdr_buf = (char *)(calloc(hdr_buf_size, 1));

if (!hdr_buf) {
res = CURLE_FAILED_INIT;
goto cleanup;
}

sprintf(hdr_buf, "X-Auth-User: %s", opt_swift_user);
snprintf(hdr_buf, hdr_buf_size, "X-Auth-User: %s", opt_swift_user);
slist = curl_slist_append(slist, hdr_buf);

sprintf(hdr_buf, "X-Auth-Key: %s", opt_swift_key);
snprintf(hdr_buf, hdr_buf_size, "X-Auth-Key: %s", opt_swift_key);
slist = curl_slist_append(slist, hdr_buf);

curl_easy_setopt(curl, CURLOPT_VERBOSE, opt_verbose);
Expand Down
13 changes: 7 additions & 6 deletions extra/mariabackup/xtrabackup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4195,7 +4195,8 @@ os_file_readdir_next_file(
return -1;
}

sprintf(full_path, "%s/%s", dirname, ent->d_name);
snprintf(full_path, strlen(dirname) + strlen(ent->d_name) + 10,
"%s/%s", dirname, ent->d_name);

ret = stat(full_path, &statinfo);

Expand Down Expand Up @@ -4994,14 +4995,14 @@ bool Backup_datasinks::backup_low()
if (xtrabackup_extra_lsndir) {
char filename[FN_REFLEN];

sprintf(filename, "%s/%s", xtrabackup_extra_lsndir,
snprintf(filename, sizeof(filename), "%s/%s", xtrabackup_extra_lsndir,
MB_METADATA_FILENAME);
if (!xtrabackup_write_metadata(filename)) {
msg("Error: failed to write metadata "
"to '%s'.", filename);
return false;
}
sprintf(filename, "%s/%s", xtrabackup_extra_lsndir,
snprintf(filename, sizeof(filename), "%s/%s", xtrabackup_extra_lsndir,
MB_INFO);
if (!write_xtrabackup_info(m_data,
mysql_connection, filename, false, false)) {
Expand Down Expand Up @@ -6999,7 +7000,7 @@ static bool xtrabackup_prepare_func(char** argv)
if (xtrabackup_incremental)
{
char inc_filename[FN_REFLEN];
sprintf(inc_filename, "%s/%s", xtrabackup_incremental_dir,
snprintf(inc_filename, sizeof(inc_filename), "%s/%s", xtrabackup_incremental_dir,
MB_CORRUPTED_PAGES_FILE);
corrupted_pages.read_from_file(inc_filename);
}
Expand Down Expand Up @@ -7068,14 +7069,14 @@ static bool xtrabackup_prepare_func(char** argv)
metadata_last_lsn = incremental_last_lsn;
}

sprintf(filename, "%s/%s", xtrabackup_target_dir, MB_METADATA_FILENAME);
snprintf(filename, sizeof(filename), "%s/%s", xtrabackup_target_dir, MB_METADATA_FILENAME);
if (!xtrabackup_write_metadata(filename)) {

msg("mariabackup: Error: failed to write metadata "
"to '%s'", filename);
ok = false;
} else if (xtrabackup_extra_lsndir) {
sprintf(filename, "%s/%s", xtrabackup_extra_lsndir, MB_METADATA_FILENAME);
snprintf(filename, sizeof(filename), "%s/%s", xtrabackup_extra_lsndir, MB_METADATA_FILENAME);
if (!xtrabackup_write_metadata(filename)) {
msg("mariabackup: Error: failed to write "
"metadata to '%s'", filename);
Expand Down
Loading