1
0
mirror of https://github.com/MariaDB/server.git synced 2026-10-23 18:49:29 +03:00

MDEV-39173 Replace sprintf with snprintf, remove deprecated pragma

Remove the unscoped #pragma GCC diagnostic ignored
"-Wdeprecated-declarations" from include/violite.h and replace all
sprintf/vsprintf calls with snprintf/vsnprintf across the codebase.

Where possible, pass actual buffer sizes as function parameters
instead of using hardcoded constants or recomputing strlen().
Notable API changes:
- get_date(): added to_len parameter for buffer size
- nice_time(), end_timer() in client/mysql.cc: added buff_size
- generate_new_name(): added name_size parameter
- calc_md5(): added buffer_size parameter (fixes off-by-one)
- MD5_HASH_TO_STRING macro: added _size parameter
- Added MYSQL_UDF_MAX_RESULT_LENGTH constant in mysql_com.h

Also fixed a pre-existing bug in sql/rpl_mi.cc where the ellipsis
"..." was written to the wrong buffer (dbuff instead of buff).

Vendored code is excluded: extra/readline, extra/wolfssl,
wsrep-lib, libmariadb, storage/mroonga/vendor, zlib.
This commit is contained in:
Mikhail Pochatkin
2026-04-07 14:55:35 +03:00
committed by Daniel Black
parent ceaef36bab
commit cbcff6324a
153 changed files with 909 additions and 748 deletions

View File

@@ -1162,8 +1162,9 @@ static void print_table_data_xml(MYSQL_RES *result);
static void print_tab_data(MYSQL_RES *result);
static void print_table_data_vertically(MYSQL_RES *result);
static void print_warnings(void);
static void end_timer(ulonglong start_time, char *buff);
static void nice_time(double sec,char *buff,bool part_second);
static void end_timer(ulonglong start_time, char *buff, size_t buff_size);
static void nice_time(double sec, char *buff, size_t buff_size,
bool part_second);
extern "C" sig_handler mysql_end(int sig) __attribute__ ((noreturn));
extern "C" sig_handler handle_sigint(int sig);
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
@@ -1418,10 +1419,13 @@ int main(int argc,char *argv[])
histfile=my_strdup(PSI_NOT_INSTRUMENTED, getenv("MYSQL_HISTFILE"),MYF(MY_WME));
else if (getenv("HOME"))
{
size_t histfile_size=
strlen(getenv("HOME")) + strlen("/.mysql_history") + 2;
histfile=(char*) my_malloc(PSI_NOT_INSTRUMENTED,
strlen(getenv("HOME")) + strlen("/.mysql_history")+2, MYF(MY_WME));
histfile_size, MYF(MY_WME));
if (histfile)
sprintf(histfile,"%s/.mysql_history",getenv("HOME"));
snprintf(histfile, histfile_size,
"%s/.mysql_history", getenv("HOME"));
char link_name[FN_REFLEN];
if (my_readlink(link_name, histfile, 0) == 0 &&
strncmp(link_name, "/dev/null", 10) == 0)
@@ -3661,7 +3665,7 @@ static int com_go(String *buffer, char *)
}
if (verbose >= 3 || !opt_silent)
end_timer(timer, time_buff);
end_timer(timer, time_buff, sizeof(time_buff));
else
time_buff[0]= '\0';
@@ -3697,9 +3701,9 @@ static int com_go(String *buffer, char *)
print_tab_data(result);
else
print_table_data(result);
snprintf(buff, sizeof(buff), "%ld %s in set",
(long) mysql_num_rows(result),
(long) mysql_num_rows(result) == 1 ? "row" : "rows");
snprintf(buff, sizeof(buff), "%llu %s in set",
(unsigned long long) mysql_num_rows(result),
mysql_num_rows(result) == 1 ? "row" : "rows");
end_pager();
if (mysql_errno(&mysql))
{
@@ -3713,7 +3717,7 @@ static int com_go(String *buffer, char *)
strmov(buff,"Query OK");
else
snprintf(buff, sizeof(buff), "Query OK, %llu %s affected",
mysql_affected_rows(&mysql),
(unsigned long long) mysql_affected_rows(&mysql),
mysql_affected_rows(&mysql) == 1 ? "row" : "rows");
pos=strend(buff);
@@ -3890,7 +3894,7 @@ static char *fieldflags2str(uint f) {
ff2s_check_flag(ON_UPDATE_NOW);
#undef ff2s_check_flag
if (f)
snprintf(s, sizeof(buf), " unknows=0x%04x", f);
snprintf(s, sizeof(buf) - (size_t)(s - buf), " unknown=0x%04x", f);
return buf;
}
@@ -4604,8 +4608,10 @@ com_edit(String *buffer,char *)
strxmov(buff,editor," ",filename,NullS);
if ((error= system(buff)))
{
char errmsg[100];
snprintf(errmsg, sizeof(errmsg), "Command '%.40s' failed", buff);
#define EDITOR_FAIL_MSG "Command '%.40s' failed"
char errmsg[sizeof(EDITOR_FAIL_MSG) - 1 + 40];
snprintf(errmsg, sizeof(errmsg), EDITOR_FAIL_MSG, buff);
#undef EDITOR_FAIL_MSG
put_info(errmsg, INFO_ERROR, 0, NullS);
goto err;
}
@@ -5289,7 +5295,7 @@ static int com_status(String *, char *)
tee_fprintf(stdout, "%.*s\t\t\t", (int) (pos-status_str), status_str);
if ((status_str= str2int(pos,10,0,LONG_MAX,(long*) &sec)))
{
nice_time((double) sec,buff,0);
nice_time((double) sec,buff, sizeof(buff),0);
tee_puts(buff, stdout); /* print nice time */
while (*status_str == ' ')
status_str++; /* to next info */
@@ -5508,8 +5514,10 @@ void tee_putc(int c, FILE *file)
len("4294967296 days, 23 hours, 59 minutes, 60.000 seconds") -> 53
*/
static void nice_time(double sec, char *buff, bool part_second)
static void nice_time(double sec, char *buff, size_t buff_size,
bool part_second)
{
char *buff_end= buff + buff_size;
ulong tmp;
if (sec >= 3600.0*24)
{
@@ -5533,21 +5541,23 @@ 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, buff_end - buff, "%.3f sec", sec);
else
sprintf(buff,"%d sec",(int) sec);
snprintf(buff, buff_end - buff, "%d sec", (int) sec);
}
static void end_timer(ulonglong start_time, char *buff)
static void end_timer(ulonglong start_time, char *buff, size_t buff_size)
{
double sec;
if (buff_size < 4)
return;
buff[0]=' ';
buff[1]='(';
sec= (microsecond_interval_timer() - start_time) / (double) (1000 * 1000);
nice_time(sec, buff + 2, 1);
strmov(strend(buff),")");
nice_time(sec, buff + 2, buff_size - 2, 1);
snprintf(strend(buff), buff_size - (strend(buff) - buff), ")");
}
static const char *construct_prompt()

View File

@@ -752,7 +752,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
if (opt_shutdown_wait_for_slaves)
{
sprintf(buff, "SHUTDOWN WAIT FOR ALL SLAVES");
snprintf(buff, sizeof(buff), "SHUTDOWN WAIT FOR ALL SLAVES");
if (mysql_query(mysql, buff))
{
my_printf_error(0, "%s failed; error: '%-.200s'",

View File

@@ -318,13 +318,14 @@ class Load_log_processor
@retval -1 Error (can't find new filename).
@retval >=0 Found file.
*/
File create_unique_file(char *filename, char *file_name_end)
File create_unique_file(char *filename, char *file_name_end,
size_t buf_remaining)
{
File res;
/* If we have to try more than 1000 times, something is seriously wrong */
for (uint version= 0; version<1000; version++)
{
sprintf(file_name_end,"-%x",version);
snprintf(file_name_end, buf_remaining, "-%x", version);
if ((res= my_create(filename,0,
O_CREAT|O_EXCL|O_BINARY|O_WRONLY,MYF(0)))!=-1)
return res;
@@ -462,7 +463,8 @@ File Load_log_processor::prepare_new_file_for_old_format(Load_log_event *le,
len= strlen(filename);
tail= filename + len;
if ((file= create_unique_file(filename,tail)) < 0)
if ((file= create_unique_file(filename, tail,
FN_REFLEN + 1 - len)) < 0)
{
error("Could not construct local filename %s.",filename);
return -1;
@@ -587,7 +589,8 @@ Exit_status Load_log_processor::process_first_event(const char *bname,
//so the rest of fname has size full_len - target_dir_name_len
ptr+= snprintf(ptr, full_len - target_dir_name_len, "-%x", file_id);
if ((file= create_unique_file(fname,ptr)) < 0)
if ((file= create_unique_file(fname, ptr,
full_len - (size_t) (ptr - fname))) < 0)
{
error("Could not construct local filename %s%s.",
target_dir_name,bname);
@@ -1460,7 +1463,6 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev,
exit(1);
}
memset(tmp_sql, 0, sizeof(tmp_sql));
snprintf(tmp_sql, sizeof(tmp_sql), " "
"SELECT Group_concat(cols) "
"FROM (SELECT 'op_type char(1)' cols "
@@ -1507,11 +1509,9 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev,
}
else
{
memset(tmp_sql, 0, sizeof(tmp_sql));
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= snprintf(tmp_sql, sizeof(tmp_sql), "CREATE TABLE IF NOT EXISTS");
tmp_sql_offset+= snprintf(tmp_sql + tmp_sql_offset, sizeof(tmp_sql) - (uint) tmp_sql_offset, " `%s`.`%s` (%s) %s",
ev->get_flashback_review_dbname(),
@@ -1537,7 +1537,7 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev,
else
{
memset(tmp_str, 0, sizeof(tmp_str));
snprintf(tmp_str, sizeof(tmp_sql), "__%s", map->get_table_name());
snprintf(tmp_str, sizeof(tmp_str), "__%s", map->get_table_name());
ev->set_flashback_review_tablename(tmp_str);
}
}
@@ -2801,9 +2801,9 @@ static Exit_status check_master_version()
char buf[256];
rpl_gtid *start_gtid= &start_gtids[gtid_idx];
sprintf(buf, "%u-%u-%llu",
start_gtid->domain_id, start_gtid->server_id,
start_gtid->seq_no);
snprintf(buf, sizeof(buf), "%u-%u-%llu",
start_gtid->domain_id, start_gtid->server_id,
start_gtid->seq_no);
query_str.append(buf, strlen(buf));
if (gtid_idx < n_start_gtids - 1)
query_str.append(',');

View File

@@ -838,7 +838,7 @@ static void write_footer(FILE *sql_file)
if (opt_dump_date)
{
char time_str[20];
get_date(time_str, GETDATE_DATE_TIME, 0);
get_date(time_str, sizeof(time_str), GETDATE_DATE_TIME, 0);
print_comment(sql_file, 0, "-- Dump completed on %s\n", time_str);
}
else
@@ -6165,7 +6165,8 @@ const char fmt_gtid_pos[]= "%sSET GLOBAL gtid_slave_pos='%s';\n";
static int do_show_master_status(MYSQL *mysql_con, int consistent_binlog_pos,
int have_mariadb_gtid, int use_gtid,
char *set_gtid_pos)
char *set_gtid_pos,
size_t set_gtid_pos_size)
{
MYSQL_ROW row;
MYSQL_RES *UNINIT_VAR(master);
@@ -6240,8 +6241,8 @@ static int do_show_master_status(MYSQL *mysql_con, int consistent_binlog_pos,
"CHANGE-MASTER settings to the slave gtid state is printed "
"later in the file.\n");
}
sprintf(set_gtid_pos, fmt_gtid_pos,
(!use_gtid ? "-- " : comment_prefix), gtid_pos);
snprintf(set_gtid_pos, set_gtid_pos_size, fmt_gtid_pos,
(!use_gtid ? "-- " : comment_prefix), gtid_pos);
}
/* SHOW MASTER STATUS reports file and position */
@@ -6331,7 +6332,8 @@ static int add_slave_statements(void)
}
static int do_show_slave_status(MYSQL *mysql_con, int have_mariadb_gtid,
int use_gtid, char* set_gtid_pos)
int use_gtid, char *set_gtid_pos,
size_t set_gtid_pos_size)
{
MYSQL_RES *UNINIT_VAR(slave);
MYSQL_ROW row;
@@ -6376,7 +6378,8 @@ static int do_show_slave_status(MYSQL *mysql_con, int have_mariadb_gtid,
"\n-- A corresponding to the below dump-slave "
"CHANGE-MASTER settings to the slave gtid state is printed "
"later in the file.\n");
sprintf(set_gtid_pos, fmt_gtid_pos, gtid_comment_prefix, gtid_pos);
snprintf(set_gtid_pos, set_gtid_pos_size, fmt_gtid_pos,
gtid_comment_prefix, gtid_pos);
}
if (use_gtid)
print_comment(md_result_file, 0,
@@ -7248,11 +7251,15 @@ int main(int argc, char **argv)
if (opt_master_data && do_show_master_status(mysql, consistent_binlog_pos,
have_mariadb_gtid,
opt_use_gtid, master_set_gtid_pos))
opt_use_gtid,
master_set_gtid_pos,
sizeof(master_set_gtid_pos)))
goto err;
if (opt_slave_data && do_show_slave_status(mysql,
have_mariadb_gtid,
opt_use_gtid, slave_set_gtid_pos))
opt_use_gtid,
slave_set_gtid_pos,
sizeof(slave_set_gtid_pos)))
goto err;
if (opt_single_transaction && do_unlock_tables(mysql)) /* unlock but no commit! */
goto err;

View File

@@ -378,9 +378,9 @@ static int write_to_table(char *filename, MYSQL *mysql)
}
mysql_real_escape_string(mysql, escaped_name, hard_path,
(unsigned long) strlen(hard_path));
sprintf(sql_statement, "LOAD DATA %s %s INFILE '%s'",
opt_low_priority ? "LOW_PRIORITY" : "",
opt_local_file ? "LOCAL" : "", escaped_name);
snprintf(sql_statement, sizeof(sql_statement), "LOAD DATA %s %s INFILE '%s'",
opt_low_priority ? "LOW_PRIORITY" : "",
opt_local_file ? "LOCAL" : "", escaped_name);
end= strend(sql_statement);
if (replace)
end= strmov(end, " REPLACE");

View File

@@ -2908,7 +2908,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);
}
@@ -2970,7 +2970,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);
}
@@ -5234,7 +5234,8 @@ 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'");
snprintf(query_buf, sizeof(query_buf), "select master_pos_wait('%s', %ld, %d, '%s')",
snprintf(query_buf, sizeof(query_buf),
"select master_pos_wait('%s', %ld, %d, '%s')",
master_pos.file, master_pos.pos + offset, timeout,
connection_name);
@@ -10821,7 +10822,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)
{

View File

@@ -1747,7 +1747,7 @@ copy_back()
for (uint i = 1; i <= TRX_SYS_MAX_UNDO_SPACES; i++) {
char filename[20];
sprintf(filename, "undo%03u", i);
snprintf(filename, sizeof(filename), "undo%03u", i);
if (!file_exists(filename)) {
break;
}

View File

@@ -148,7 +148,7 @@ xb_mysql_connect()
char mysql_port_str[std::numeric_limits<int>::digits10 + 3];
const char *user= opt_user ? opt_user : get_os_user();
sprintf(mysql_port_str, "%d", opt_port);
snprintf(mysql_port_str, sizeof(mysql_port_str), "%d", opt_port);
if (connection == NULL) {
msg("Failed to init MariaDB struct: %s.",

View File

@@ -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;
}

View File

@@ -491,7 +491,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;
@@ -549,6 +549,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) {
@@ -565,18 +566,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);

View File

@@ -4141,13 +4141,15 @@ next_file:
strcpy(info->name, ent->d_name);
size_t full_path_size= strlen(dirname) + strlen(ent->d_name) + 10;
full_path = static_cast<char*>(
ut_malloc_nokey(strlen(dirname) + strlen(ent->d_name) + 10));
ut_malloc_nokey(full_path_size));
if (!full_path) {
return -1;
}
sprintf(full_path, "%s/%s", dirname, ent->d_name);
snprintf(full_path, full_path_size,
"%s/%s", dirname, ent->d_name);
ret = stat(full_path, &statinfo);
@@ -4949,14 +4951,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,
XTRABACKUP_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,
XTRABACKUP_INFO);
if (!write_xtrabackup_info(m_data,
mysql_connection, filename, false, false)) {
@@ -6820,8 +6822,8 @@ static bool xtrabackup_prepare_func(char** argv)
/*
read metadata of target
*/
sprintf(metadata_path, "%s/%s", xtrabackup_target_dir,
XTRABACKUP_METADATA_FILENAME);
snprintf(metadata_path, sizeof(metadata_path), "%s/%s",
xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
if (!xtrabackup_read_metadata(metadata_path)) {
msg("Error: failed to read metadata from '%s'\n",
@@ -6931,7 +6933,7 @@ error:
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);
}
@@ -7000,14 +7002,14 @@ error:
metadata_last_lsn = incremental_last_lsn;
}
sprintf(filename, "%s/%s", xtrabackup_target_dir, XTRABACKUP_METADATA_FILENAME);
snprintf(filename, sizeof(filename), "%s/%s", xtrabackup_target_dir, XTRABACKUP_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, XTRABACKUP_METADATA_FILENAME);
snprintf(filename, sizeof(filename), "%s/%s", xtrabackup_extra_lsndir, XTRABACKUP_METADATA_FILENAME);
if (!xtrabackup_write_metadata(filename)) {
msg("mariabackup: Error: failed to write "
"metadata to '%s'", filename);
@@ -7781,7 +7783,9 @@ static int main_low(char** argv)
} else if (xtrabackup_backup && xtrabackup_incremental_basedir) {
char filename[FN_REFLEN];
sprintf(filename, "%s/%s", xtrabackup_incremental_basedir, XTRABACKUP_METADATA_FILENAME);
snprintf(filename, sizeof(filename), "%s/%s",
xtrabackup_incremental_basedir,
XTRABACKUP_METADATA_FILENAME);
if (!xtrabackup_read_metadata(filename)) {
msg("mariabackup: error: failed to read metadata from "
@@ -7794,7 +7798,9 @@ static int main_low(char** argv)
} else if (xtrabackup_prepare && xtrabackup_incremental_dir) {
char filename[FN_REFLEN];
sprintf(filename, "%s/%s", xtrabackup_incremental_dir, XTRABACKUP_METADATA_FILENAME);
snprintf(filename, sizeof(filename), "%s/%s",
xtrabackup_incremental_dir,
XTRABACKUP_METADATA_FILENAME);
if (!xtrabackup_read_metadata(filename)) {
msg("mariabackup: error: failed to read metadata from "

View File

@@ -767,7 +767,8 @@ extern int wild_compare(const char *str,const char *wildstr,
pbool str_is_pattern);
extern my_bool array_append_string_unique(const char *str,
const char **array, size_t size);
extern void get_date(char * to,int timeflag,time_t use_time);
extern void get_date(char * to, size_t to_len, int timeflag,
time_t use_time);
extern void soundex(CHARSET_INFO *, char * out_pntr, char * in_pntr,
pbool remove_garbage);
extern int init_record_cache(RECORD_CACHE *info,size_t cachesize,File file,

View File

@@ -462,6 +462,7 @@ typedef struct st_vio Vio;
#define MAX_INT_WIDTH 10 /* Max width for a LONG w.o. sign */
#define MAX_BIGINT_WIDTH 20 /* Max width for a LONGLONG */
#define MAX_CHAR_WIDTH 255 /* Max length for a CHAR column */
#define MYSQL_UDF_MAX_RESULT_LENGTH 255 /* Max length for a UDF result */
#define MAX_BLOB_WIDTH 16777216 /* Default width for blob */
typedef struct st_net {

View File

@@ -16,6 +16,19 @@
#ifndef PASSWORD_INCLUDED
#define PASSWORD_INCLUDED
/*
SCRAMBLE_LENGTH_323 and SCRAMBLED_PASSWORD_CHAR_LENGTH_323 may
already be defined via mysql_com.h. Define them here as well so
that translation units which do not include mysql_com.h (e.g.
mariadb-install-db via libmariadb headers) can still use them.
*/
#ifndef SCRAMBLE_LENGTH_323
#define SCRAMBLE_LENGTH_323 8
#endif
#ifndef SCRAMBLED_PASSWORD_CHAR_LENGTH_323
#define SCRAMBLED_PASSWORD_CHAR_LENGTH_323 (SCRAMBLE_LENGTH_323 * 2)
#endif
C_MODE_START
void my_make_scrambled_password_323(char *to, const char *password,

View File

@@ -141,11 +141,6 @@ int vio_getnameinfo(const struct sockaddr *sa,
int flags);
#ifdef HAVE_OPENSSL
/* apple deprecated openssl in MacOSX Lion */
#ifdef __APPLE__
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
#define HEADER_DES_LOCL_H dummy_something
#define YASSL_MYSQL_COMPATIBLE
#ifndef YASSL_PREFIX

View File

@@ -237,7 +237,8 @@ int main(int argc, char* const argv[] )
sigaction(SIGCHLD, &sa,NULL);
sigaction(SIGABRT, &sa_abort,NULL);
sprintf(safe_process_name, "safe_process[%ld]", (long) own_pid);
snprintf(safe_process_name, sizeof(safe_process_name),
"safe_process[%ld]", (long) own_pid);
message("Started");

View File

@@ -181,7 +181,7 @@ int main(int argc, const char** argv )
PROCESS_INFORMATION process_info= {0};
BOOL nocore= FALSE;
sprintf(safe_process_name, "safe_process[%lu]", pid);
snprintf(safe_process_name, sizeof(safe_process_name), "safe_process[%lu]", pid);
/* Create an event for the signal handler */
if ((shutdown_event=

View File

@@ -109,9 +109,11 @@ int logger_close(LOGGER_HANDLE *log)
}
static char *logname(LOGGER_HANDLE *log, char *buf, unsigned int n_log)
static char *logname(LOGGER_HANDLE *log, char *buf, size_t buf_size,
unsigned int n_log)
{
sprintf(buf+log->path_len, ".%0*u", n_dig(log->rotations), n_log);
snprintf(buf + log->path_len, buf_size - log->path_len,
".%0*u", n_dig(log->rotations), n_log);
return buf;
}
@@ -128,11 +130,11 @@ static int do_rotate(LOGGER_HANDLE *log)
memcpy(namebuf, log->path, log->path_len);
buf_new= logname(log, namebuf, log->rotations);
buf_new= logname(log, namebuf, sizeof(namebuf), log->rotations);
buf_old= log->path;
for (i=log->rotations-1; i>0; i--)
{
logname(log, buf_old, i);
logname(log, buf_old, FN_REFLEN, i);
if (!access(buf_old, F_OK) &&
(result= my_rename(buf_old, buf_new, MYF(0))))
goto exit;
@@ -143,7 +145,7 @@ static int do_rotate(LOGGER_HANDLE *log)
if ((result= my_close(log->file, MYF(0))))
goto exit;
namebuf[log->path_len]= 0;
result= my_rename(namebuf, logname(log, log->path, 1), MYF(0));
result= my_rename(namebuf, logname(log, log->path, FN_REFLEN, 1), MYF(0));
log->file= my_open(namebuf, LOG_FLAGS, MYF(0));
exit:
errno= my_errno;

View File

@@ -35,7 +35,7 @@
*/
void get_date(register char * to, int flag, time_t date)
void get_date(register char * to, size_t to_len, int flag, time_t date)
{
reg2 struct tm *start_time;
time_t skr;
@@ -57,26 +57,33 @@ void get_date(register char * to, int flag, time_t date)
start_time= localtime(&skr);
#endif
if (flag & GETDATE_SHORT_DATE)
sprintf(to,"%02d%02d%02d",
start_time->tm_year % 100,
start_time->tm_mon+1,
start_time->tm_mday);
snprintf(to, to_len, "%02d%02d%02d",
start_time->tm_year % 100,
start_time->tm_mon+1,
start_time->tm_mday);
else
sprintf(to, ((flag & GETDATE_FIXEDLENGTH) ?
"%4d-%02d-%02d" : "%d-%02d-%02d"),
start_time->tm_year+1900,
start_time->tm_mon+1,
start_time->tm_mday);
snprintf(to, to_len,
((flag & GETDATE_FIXEDLENGTH) ?
"%4d-%02d-%02d" : "%d-%02d-%02d"),
start_time->tm_year+1900,
start_time->tm_mon+1,
start_time->tm_mday);
if (flag & GETDATE_DATE_TIME)
sprintf(strend(to),
((flag & GETDATE_FIXEDLENGTH) ?
" %02d:%02d:%02d" : " %2d:%02d:%02d"),
start_time->tm_hour,
start_time->tm_min,
start_time->tm_sec);
{
size_t l= strlen(to);
snprintf(to + l, to_len - l,
((flag & GETDATE_FIXEDLENGTH) ?
" %02d:%02d:%02d" : " %2d:%02d:%02d"),
start_time->tm_hour,
start_time->tm_min,
start_time->tm_sec);
}
else if (flag & GETDATE_HHMMSSTIME)
sprintf(strend(to),"%02d%02d%02d",
start_time->tm_hour,
start_time->tm_min,
start_time->tm_sec);
{
size_t l= strlen(to);
snprintf(to + l, to_len - l, "%02d%02d%02d",
start_time->tm_hour,
start_time->tm_min,
start_time->tm_sec);
}
} /* get_date */

View File

@@ -310,8 +310,9 @@ static my_bool test_if_sfx_card_exists()
{
struct stat stat_buff;
sprintf(sfx_devices[sfx_found_devices].dev_name, "/dev/sfdv%dn1",
dev_num);
snprintf(sfx_devices[sfx_found_devices].dev_name,
sizeof(sfx_devices[sfx_found_devices].dev_name),
"/dev/sfdv%dn1", dev_num);
if (stat(sfx_devices[sfx_found_devices].dev_name, &stat_buff) < 0)
break;

View File

@@ -144,7 +144,15 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
dp= (struct dirent*) dirent_tmp;
/* readdir_r is deprecated on macOS but still used for older platforms */
#ifdef __APPLE__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
while (!(READDIR(dirp,(struct dirent*) dirent_tmp,dp)))
#ifdef __APPLE__
#pragma GCC diagnostic pop
#endif
{
MY_STAT statbuf, *mystat= 0;

View File

@@ -149,7 +149,8 @@ void my_create_backup_name(char *to, const char *from, time_t backup_start)
{
char ext[MY_BACKUP_NAME_EXTRA_LENGTH+1];
ext[0]='-';
get_date(ext+1, GETDATE_SHORT_DATE | GETDATE_HHMMSSTIME, backup_start);
get_date(ext+1, sizeof(ext) - 1, GETDATE_SHORT_DATE | GETDATE_HHMMSSTIME,
backup_start);
strmov(strend(ext),REDEL_EXT);
strmov(strmov(to, from), ext);
}

View File

@@ -81,7 +81,7 @@ static int do_test()
{
n1=rnd(1000); n2=rnd(100); n3=rnd(MY_MIN(recant*5,MAX_RECORDS));
record= (char*) my_malloc(reclength,MYF(MY_FAE));
sprintf(record,"%6d:%4d:%8d:Pos: %4d ",n1,n2,n3,write_count);
snprintf(record, reclength, "%6d:%4d:%8d:Pos: %4d ",n1,n2,n3,write_count);
if (my_hash_insert(&hash,record))
{
printf("Error: %d in write at record: %d\n",my_errno,i);
@@ -102,7 +102,7 @@ static int do_test()
for (j=rnd(1000) ; j>0 && key1[j] == 0 ; j--) ;
if (j != 0)
{
sprintf(key,"%6d",j);
snprintf(key, sizeof(key), "%6d",j);
if (!(recpos=hash_search(&hash,key,0)))
{
printf("can't find key1: \"%s\"\n",key);
@@ -137,7 +137,7 @@ static int do_test()
for (j=rnd(1000) ; j>0 && key1[j] == 0 ; j--) ;
if (j)
{
sprintf(key,"%6d",j);
snprintf(key, sizeof(key), "%6d",j);
if (!(recpos=hash_search(&hash,key,0)))
{
printf("can't find key1: \"%s\"\n",key);
@@ -146,7 +146,7 @@ static int do_test()
key1[atoi(recpos)]--;
key_check=key_check-atoi(recpos)+n1;
key1[n1]++;
sprintf(recpos,"%6d:%4d:%8d:XXX: %4d ",n1,n2,n3,update);
snprintf(recpos, reclength, "%6d:%4d:%8d:XXX: %4d ",n1,n2,n3,update);
update++;
if (hash_update(&hash,recpos,key,0))
{
@@ -175,7 +175,7 @@ static int do_test()
{
HASH_SEARCH_STATE state;
printf("- Testing identical read\n");
sprintf(key,"%6d",j);
snprintf(key, sizeof(key), "%6d",j);
pos=1;
if (!(recpos= hash_first(&hash, key, 0, &state)))
{

View File

@@ -104,15 +104,15 @@ static int uname(struct utsname *buf)
buf->nodename[0]= 0;
strcpy(buf->sysname, "Windows");
sprintf(buf->release, "%d.%d", (int)ver.dwMajorVersion, (int)ver.dwMinorVersion);
snprintf(buf->release, sizeof(buf->release), "%d.%d", (int)ver.dwMajorVersion, (int)ver.dwMinorVersion);
const char *version_str= get_os_version_name(&ver);
if(version_str && version_str[0])
sprintf(buf->version, "%s %s",version_str, ver.szCSDVersion);
snprintf(buf->version, sizeof(buf->version), "%s %s",version_str, ver.szCSDVersion);
else
{
/* Fallback for unknown versions, e.g "Windows <major_ver>.<minor_ver>" */
sprintf(buf->version, "Windows %d.%d%s",
snprintf(buf->version, sizeof(buf->version), "Windows %d.%d%s",
(int)ver.dwMajorVersion, (int)ver.dwMinorVersion,
(ver.wProductType == VER_NT_WORKSTATION ? "" : " Server"));
}

View File

@@ -494,7 +494,7 @@ size_t Inet6::to_string(char *dst, size_t dstsize) const
//
// If it is not the last field, append closing ':'.
p += sprintf(p, "%x", ipv6_words[i]);
p += snprintf(p, dstend - p, "%x", ipv6_words[i]);
if (i + 1 != IN6_ADDR_NUM_WORDS)
{

View File

@@ -6664,11 +6664,15 @@ longlong Field_year::val_int(void)
String *Field_year::val_str(String *val_buffer,
String *val_ptr __attribute__((unused)))
{
DBUG_ASSERT(field_length < 5);
val_buffer->alloc(5);
/* "YYYY" + NUL terminator */
static const size_t YEAR_STR_BUFF_LEN= 5;
DBUG_ASSERT(field_length < YEAR_STR_BUFF_LEN);
val_buffer->alloc(YEAR_STR_BUFF_LEN);
val_buffer->length(field_length);
char *to=(char*) val_buffer->ptr();
sprintf(to,field_length == 2 ? "%02d" : "%04d",(int) Field_year::val_int());
snprintf(to, YEAR_STR_BUFF_LEN,
field_length == 2 ? "%02d" : "%04d",
(int) Field_year::val_int());
val_buffer->set_charset(&my_charset_numeric);
return val_buffer;
}

View File

@@ -100,9 +100,10 @@ const char *gcalc_ev_name(int ev)
}
static int gcalc_pi_str(char *str, const Gcalc_heap::Info *pi, const char *postfix)
static int gcalc_pi_str(char *str, size_t size,
const Gcalc_heap::Info *pi, const char *postfix)
{
return sprintf(str, "%s %d %d | %s %d %d%s",
return snprintf(str, size, "%s %d %d | %s %d %d%s",
GCALC_SIGN(pi->node.shape.ix[0]) ? "-":"", FIRST_DIGIT(pi->node.shape.ix[0]),pi->node.shape.ix[1],
GCALC_SIGN(pi->node.shape.iy[0]) ? "-":"", FIRST_DIGIT(pi->node.shape.iy[0]),pi->node.shape.iy[1],
postfix);
@@ -132,7 +133,7 @@ static void GCALC_DBUG_PRINT_PI(const Gcalc_heap::Info *pi)
#endif
return;
}
n_buf= gcalc_pi_str(buf, pi, "");
n_buf= gcalc_pi_str(buf, sizeof(buf), pi, "");
buf[n_buf]= 0;
GCALC_DBUG_PRINT(("%s", buf));
}
@@ -148,14 +149,16 @@ static void GCALC_DBUG_PRINT_SLICE(const char *header,
for (; slice; slice= slice->get_next())
{
size_t lnbuf= nbuf;
lnbuf+= sprintf(buf + lnbuf, "%d\t", slice->thread);
lnbuf+= sprintf(buf + lnbuf, "%s\t", gcalc_ev_name(slice->event));
lnbuf+= snprintf(buf + lnbuf, sizeof(buf) - lnbuf, "%d\t", slice->thread);
lnbuf+= snprintf(buf + lnbuf, sizeof(buf) - lnbuf, "%s\t",
gcalc_ev_name(slice->event));
lnbuf+= gcalc_pi_str(buf + lnbuf, slice->pi, "\t");
lnbuf+= gcalc_pi_str(buf + lnbuf, sizeof(buf) - lnbuf, slice->pi, "\t");
if (slice->is_bottom())
lnbuf+= sprintf(buf+lnbuf, "bt\t");
lnbuf+= snprintf(buf + lnbuf, sizeof(buf) - lnbuf, "bt\t");
else
lnbuf+= gcalc_pi_str(buf+lnbuf, slice->next_pi, "\t");
lnbuf+= gcalc_pi_str(buf + lnbuf, sizeof(buf) - lnbuf,
slice->next_pi, "\t");
buf[lnbuf]= 0;
GCALC_DBUG_PRINT(("%s", buf));
}

View File

@@ -1279,8 +1279,8 @@ Item_singlerow_subselect::select_transformer(JOIN *join)
if (thd->lex->describe)
{
char warn_buff[MYSQL_ERRMSG_SIZE];
sprintf(warn_buff, ER_THD(thd, ER_SELECT_REDUCED),
select_lex->select_number);
snprintf(warn_buff, sizeof(warn_buff), ER_THD(thd, ER_SELECT_REDUCED),
select_lex->select_number);
push_warning(thd, Sql_condition::WARN_LEVEL_NOTE,
ER_SELECT_REDUCED, warn_buff);
}
@@ -2069,8 +2069,8 @@ Item_in_subselect::single_value_transformer(JOIN *join)
if (thd->lex->describe)
{
char warn_buff[MYSQL_ERRMSG_SIZE];
sprintf(warn_buff, ER_THD(thd, ER_SELECT_REDUCED),
select_lex->select_number);
snprintf(warn_buff, sizeof(warn_buff), ER_THD(thd, ER_SELECT_REDUCED),
select_lex->select_number);
push_warning(thd, Sql_condition::WARN_LEVEL_NOTE,
ER_SELECT_REDUCED, warn_buff);
}

View File

@@ -629,11 +629,12 @@ static bool make_date_time(const String *format, const MYSQL_TIME *l_time,
str->append(hours_i < 12 ? "AM" : "PM",2);
break;
case 'r':
length= sprintf(intbuff, ((l_time->hour % 24) < 12) ?
"%02d:%02d:%02d AM" : "%02d:%02d:%02d PM",
(l_time->hour+11)%12+1,
l_time->minute,
l_time->second);
length= snprintf(intbuff, sizeof(intbuff),
((l_time->hour % 24) < 12) ?
"%02d:%02d:%02d AM" : "%02d:%02d:%02d PM",
(l_time->hour+11)%12+1,
l_time->minute,
l_time->second);
str->append(intbuff, length);
break;
case 'S':
@@ -641,8 +642,8 @@ static bool make_date_time(const String *format, const MYSQL_TIME *l_time,
str->append_zerofill(l_time->second, 2);
break;
case 'T':
length= sprintf(intbuff, "%02d:%02d:%02d",
l_time->hour, l_time->minute, l_time->second);
length= snprintf(intbuff, sizeof(intbuff), "%02d:%02d:%02d",
l_time->hour, l_time->minute, l_time->second);
str->append(intbuff, length);
break;
case 'U':
@@ -3576,8 +3577,9 @@ bool Item_func_maketime::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzy
check_time_range(ltime, decimals, &unused);
char buf[28];
char *ptr= longlong10_to_str(hour.value(), buf, hour.is_unsigned() ? 10 : -10);
int len = (int)(ptr - buf) + sprintf(ptr, ":%02u:%02u",
(uint) minute, (uint) sec.sec());
int len = (int)(ptr - buf) + snprintf(ptr, buf + sizeof(buf) - ptr,
":%02u:%02u",
(uint) minute, (uint) sec.sec());
ErrConvString err(buf, len, &my_charset_bin);
thd->push_warning_truncated_wrong_value("time", err.ptr());
}

View File

@@ -2937,7 +2937,8 @@ static void setup_windows_event_source()
nonzero if not possible to get unique filename.
*/
static int find_uniq_filename(char *name, ulong min_log_number_to_use,
static int find_uniq_filename(char *name, size_t name_size,
ulong min_log_number_to_use,
ulong *last_used_log_number)
{
char buff[FN_REFLEN], ext_buf[FN_REFLEN];
@@ -2996,7 +2997,7 @@ updating the index files.", max_found);
}
next= max_found + 1;
if (sprintf(ext_buf, "%06lu", next)<0)
if (snprintf(ext_buf, sizeof(ext_buf), "%06lu", next)<0)
{
error= 1;
goto end;
@@ -3017,7 +3018,7 @@ index files.", name, ext_buf, (strlen(ext_buf) + (end - name)));
goto end;
}
if (sprintf(end, "%06lu", next)<0)
if (snprintf(end, name + name_size - end, "%06lu", next)<0)
{
error= 1;
goto end;
@@ -3048,8 +3049,9 @@ bool MYSQL_LOG::init_and_set_log_file_name(const char *log_name,
{
strmov(log_file_name, new_name);
}
else if (!new_name && generate_new_name(log_file_name, log_name,
next_log_number))
else if (!new_name && generate_new_name(log_file_name,
sizeof(log_file_name),
log_name, next_log_number))
return TRUE;
return FALSE;
@@ -3262,21 +3264,23 @@ void MYSQL_LOG::cleanup()
}
int MYSQL_LOG::generate_new_name(char *new_name, const char *log_name,
int MYSQL_LOG::generate_new_name(char *new_name, size_t name_size,
const char *log_name,
ulong next_log_number)
{
fn_format(new_name, log_name, mysql_data_home, "", 4);
return 0;
}
int MYSQL_BIN_LOG::generate_new_name(char *new_name, const char *log_name,
int MYSQL_BIN_LOG::generate_new_name(char *new_name, size_t name_size,
const char *log_name,
ulong next_log_number)
{
fn_format(new_name, log_name, mysql_data_home, "", 4);
if (!fn_ext(log_name)[0])
{
if (DBUG_IF("binlog_inject_new_name_error") ||
unlikely(find_uniq_filename(new_name, next_log_number,
unlikely(find_uniq_filename(new_name, name_size, next_log_number,
&last_used_log_number)))
{
THD *thd= current_thd;
@@ -3508,8 +3512,8 @@ bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time,
my_b_write(&log_file, (uchar*) "\n", 1))
goto err;
sprintf(query_time_buff, "%.6f", ulonglong2double(query_utime)/1000000.0);
sprintf(lock_time_buff, "%.6f", ulonglong2double(lock_utime)/1000000.0);
snprintf(query_time_buff, sizeof(query_time_buff), "%.6f", ulonglong2double(query_utime)/1000000.0);
snprintf(lock_time_buff, sizeof(lock_time_buff), "%.6f", ulonglong2double(lock_utime)/1000000.0);
if (my_b_printf(&log_file,
"# Thread_id: %lu Schema: %s QC_hit: %s\n"
"# Query_time: %s Lock_time: %s Rows_sent: %lu Rows_examined: %lu\n"
@@ -3529,12 +3533,12 @@ bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time,
{
ha_handler_stats *stats= &thd->handler_stats;
double tracker_frequency= timer_tracker_frequency();
sprintf(query_time_buff, "%.4f",
1000.0 * ulonglong2double(stats->pages_read_time)/
tracker_frequency);
sprintf(lock_time_buff, "%.4f",
1000.0 * ulonglong2double(stats->engine_time)/
tracker_frequency);
snprintf(query_time_buff, sizeof(query_time_buff), "%.4f",
1000.0 * ulonglong2double(stats->pages_read_time)/
tracker_frequency);
snprintf(lock_time_buff, sizeof(lock_time_buff), "%.4f",
1000.0 * ulonglong2double(stats->engine_time)/
tracker_frequency);
if (my_b_printf(&log_file,
"# Pages_accessed: %lu Pages_read: %lu "
@@ -5654,7 +5658,8 @@ int MYSQL_BIN_LOG::new_file_impl()
We have to do this here and not in open as we want to store the
new file name in the current binary log file.
*/
if (unlikely((error= generate_new_name(new_name, name, 0))))
if (unlikely((error= generate_new_name(new_name, sizeof(new_name),
name, 0))))
{
mysql_mutex_unlock(&LOCK_index);
DBUG_RETURN(error);
@@ -7620,7 +7625,8 @@ static int do_delete_gtid_domain(DYNAMIC_ARRAY *domain_drop_lex)
if (errmsg)
goto end;
errmsg= rpl_global_gtid_binlog_state.drop_domain(domain_drop_lex,
glev, errbuf);
glev, errbuf,
sizeof(errbuf));
end:
if (errmsg)

View File

@@ -324,7 +324,8 @@ public:
const char *generate_name(const char *log_name,
const char *suffix,
bool strip_ext, char *buff);
virtual int generate_new_name(char *new_name, const char *log_name,
virtual int generate_new_name(char *new_name, size_t name_size,
const char *log_name,
ulong next_log_number);
protected:
/* LOCK_log is inited by init_pthread_objects() */
@@ -723,7 +724,8 @@ public:
int open(const char *opt_name) override;
void close() override;
int generate_new_name(char *new_name, const char *log_name,
int generate_new_name(char *new_name, size_t name_size,
const char *log_name,
ulong next_log_number) override;
int log_and_order(THD *thd, my_xid xid, bool all,
bool need_prepare_ordered, bool need_commit_ordered) override;

View File

@@ -1425,7 +1425,7 @@ code_name(int code)
case Q_XID: return "XID";
case Q_GTID_FLAGS3: return "Q_GTID_FLAGS3";
}
sprintf(buf, "CODE#%d", code);
snprintf(buf, sizeof(buf), "CODE#%d", code);
return buf;
}
#endif

View File

@@ -3230,8 +3230,8 @@ private:
@return the value of the buffer pointer
*/
inline char *serialize_xid(char *buf, long fmt, long gln, long bln,
const char *dat)
inline char *serialize_xid(char *buf, size_t bufsize, long fmt, long gln,
long bln, const char *dat)
{
int i;
char *c= buf;
@@ -3263,7 +3263,7 @@ inline char *serialize_xid(char *buf, long fmt, long gln, long bln,
c+= 2;
}
c[0]= '\'';
sprintf(c+1, ",%lu", fmt);
snprintf(c + 1, bufsize - (size_t)(c + 1 - buf), ",%lu", fmt);
return buf;
}
@@ -3284,7 +3284,8 @@ struct event_mysql_xid_t : MYSQL_XID
char buf[ser_buf_size];
char *serialize()
{
return serialize_xid(buf, formatID, gtrid_length, bqual_length, data);
return serialize_xid(buf, sizeof(buf), formatID, gtrid_length,
bqual_length, data);
}
};
@@ -3295,7 +3296,8 @@ struct event_xid_t : XID
char *serialize(char *buf_arg)
{
return serialize_xid(buf_arg, formatID, gtrid_length, bqual_length, data);
return serialize_xid(buf_arg, ser_buf_size, formatID, gtrid_length,
bqual_length, data);
}
char *serialize()
{
@@ -3347,9 +3349,9 @@ private:
int do_commit() override;
const char* get_query() override
{
sprintf(query,
(one_phase ? "XA COMMIT %s ONE PHASE" : "XA PREPARE %s"),
m_xid.serialize());
snprintf(query, sizeof(query),
(one_phase ? "XA COMMIT %s ONE PHASE" : "XA PREPARE %s"),
m_xid.serialize());
return query;
}
#endif

View File

@@ -635,7 +635,7 @@ log_event_print_value(IO_CACHE *file, PRINT_EVENT_INFO *print_event_info,
float fl;
float4get(fl, ptr);
char tmp[320];
sprintf(tmp, "%-20g", (double) fl);
snprintf(tmp, sizeof(tmp), "%-20g", (double) fl);
my_b_printf(file, "%s", tmp); /* my_snprintf doesn't support %-20g */
return 4;
}
@@ -649,7 +649,7 @@ log_event_print_value(IO_CACHE *file, PRINT_EVENT_INFO *print_event_info,
float8get(dbl, ptr);
char tmp[320];
sprintf(tmp, "%-.20g", dbl); /* strmake doesn't support %-20g */
snprintf(tmp, sizeof(tmp), "%-.20g", dbl); /* strmake doesn't support %-20g */
my_b_printf(file, tmp, "%s");
return 8;
}
@@ -2515,7 +2515,7 @@ bool User_var_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
double real_val;
char real_buf[FMT_G_BUFSIZE(14)];
float8get(real_val, val);
sprintf(real_buf, "%.14g", real_val);
snprintf(real_buf, sizeof(real_buf), "%.14g", real_val);
if (my_b_printf(&cache, ":=%s%s\n", real_buf,
print_event_info->delimiter))
goto err;
@@ -2924,10 +2924,13 @@ bool copy_cache_to_string_wrapped(IO_CACHE *cache,
sizeof(fmt_binlog2) +
3*PRINT_EVENT_INFO::max_delimiter_size;
size_t buf_alloc_size;
if (reinit_io_cache(cache, READ_CACHE, 0L, FALSE, FALSE))
goto err;
if (!(to->str= (char*) my_malloc(PSI_NOT_INSTRUMENTED, (size_t)cache->end_of_file + fmt_size,
buf_alloc_size= (size_t)cache->end_of_file + fmt_size;
if (!(to->str= (char*) my_malloc(PSI_NOT_INSTRUMENTED, buf_alloc_size,
MYF(0))))
{
perror("Out of memory: can't allocate memory in "
@@ -2956,38 +2959,45 @@ bool copy_cache_to_string_wrapped(IO_CACHE *cache,
contribution of non-compressed packet.
*/
char *str= to->str;
const char *buf_end= to->str + buf_alloc_size;
size_t add_to_len;
str += (to->length= sprintf(str, fmt_frag, 0));
str += (to->length= snprintf(str, (size_t)(buf_end - str), fmt_frag, 0));
if (my_b_read(cache, (uchar*) str, (uint32) (cache_size/2 + 1)))
goto err;
str += (add_to_len = (uint32) (cache_size/2 + 1));
to->length += add_to_len;
str += (add_to_len= sprintf(str, fmt_n_delim, delimiter));
str += (add_to_len= snprintf(str, (size_t)(buf_end - str),
fmt_n_delim, delimiter));
to->length += add_to_len;
str += (add_to_len= sprintf(str, fmt_frag, 1));
str += (add_to_len= snprintf(str, (size_t)(buf_end - str),
fmt_frag, 1));
to->length += add_to_len;
if (my_b_read(cache, (uchar*) str, uint32(cache->end_of_file - (cache_size/2 + 1))))
goto err;
str += (add_to_len= uint32(cache->end_of_file - (cache_size/2 + 1)));
to->length += add_to_len;
{
str += (add_to_len= sprintf(str , fmt_delim, delimiter));
str += (add_to_len= snprintf(str, (size_t)(buf_end - str),
fmt_delim, delimiter));
to->length += add_to_len;
}
to->length += sprintf(str, fmt_binlog2, delimiter);
to->length += snprintf(str, (size_t)(buf_end - str),
fmt_binlog2, delimiter);
}
else
{
char *str= to->str;
const char *buf_end= to->str + buf_alloc_size;
str += (to->length= sprintf(str, str_binlog));
str += (to->length= snprintf(str, (size_t)(buf_end - str), str_binlog));
if (my_b_read(cache, (uchar*) str, (size_t)cache->end_of_file))
goto err;
str += cache->end_of_file;
to->length += (size_t)cache->end_of_file;
to->length += sprintf(str , fmt_delim, delimiter);
to->length += snprintf(str, (size_t)(buf_end - str),
fmt_delim, delimiter);
}
reinit_io_cache(cache, WRITE_CACHE, 0, FALSE, TRUE);

View File

@@ -3853,7 +3853,7 @@ Gtid_log_event::pack_info(Protocol *protocol)
flags2 & FL_PREPARED_XA ? "XA START " : "BEGIN GTID "));
if (flags2 & FL_PREPARED_XA)
{
p+= sprintf(p, "%s GTID ", xid.serialize());
p+= snprintf(p, buf + sizeof(buf) - p, "%s GTID ", xid.serialize());
}
p= longlong10_to_str(domain_id, p, 10);
*p++= '-';
@@ -3940,7 +3940,7 @@ Gtid_log_event::do_apply_event(rpl_group_info *rgi)
thd->lex->xid= &xid;
thd->lex->xa_opt= XA_NONE;
sprintf(buf_xa, fmt, xid.serialize());
snprintf(buf_xa, sizeof(buf_xa), fmt, xid.serialize());
thd->set_query_and_id(buf_xa, static_cast<uint32>(strlen(buf_xa)),
&my_charset_bin, next_query_id());
thd->lex->sql_command= SQLCOM_XA_START;
@@ -4576,9 +4576,9 @@ void XA_prepare_log_event::pack_info(Protocol *protocol)
{
char query[sizeof("XA COMMIT ONE PHASE") + 1 + ser_buf_size];
sprintf(query,
(one_phase ? "XA COMMIT %s ONE PHASE" : "XA PREPARE %s"),
m_xid.serialize());
snprintf(query, sizeof(query),
(one_phase ? "XA COMMIT %s ONE PHASE" : "XA PREPARE %s"),
m_xid.serialize());
protocol->store(query, strlen(query), &my_charset_bin);
}
@@ -5227,7 +5227,7 @@ void Append_block_log_event::pack_info(Protocol *protocol)
{
char buf[256];
uint length;
length= (uint) sprintf(buf, ";file_id=%u;block_len=%u", file_id, block_len);
length= (uint) snprintf(buf, sizeof(buf), ";file_id=%u;block_len=%u", file_id, block_len);
protocol->store(buf, length, &my_charset_bin);
}
@@ -5336,7 +5336,7 @@ void Delete_file_log_event::pack_info(Protocol *protocol)
{
char buf[64];
uint length;
length= (uint) sprintf(buf, ";file_id=%u", (uint) file_id);
length= (uint) snprintf(buf, sizeof(buf), ";file_id=%u", (uint) file_id);
protocol->store(buf, (int32) length, &my_charset_bin);
}
#endif
@@ -5384,7 +5384,7 @@ void Execute_load_log_event::pack_info(Protocol *protocol)
{
char buf[64];
uint length;
length= (uint) sprintf(buf, ";file_id=%u", (uint) file_id);
length= (uint) snprintf(buf, sizeof(buf), ";file_id=%u", (uint) file_id);
protocol->store(buf, (int32) length, &my_charset_bin);
}

View File

@@ -397,14 +397,16 @@ void
print_decimal(const my_decimal *dec)
{
int i, end;
char buff[512], *pos;
char buff[512], *pos, *buf_end;
pos= buff;
pos+= sprintf(buff, "Decimal: sign: %d intg: %d frac: %d { ",
dec->sign(), dec->intg, dec->frac);
buf_end= buff + sizeof(buff);
pos+= snprintf(buff, sizeof(buff),
"Decimal: sign: %d intg: %d frac: %d { ",
dec->sign(), dec->intg, dec->frac);
end= ROUND_UP(dec->frac)+ROUND_UP(dec->intg)-1;
for (i=0; i < end; i++)
pos+= sprintf(pos, "%09d, ", dec->buf[i]);
pos+= sprintf(pos, "%09d }\n", dec->buf[i]);
pos+= snprintf(pos, buf_end - pos, "%09d, ", dec->buf[i]);
pos+= snprintf(pos, buf_end - pos, "%09d }\n", dec->buf[i]);
fputs(buff, DBUG_FILE);
}

View File

@@ -373,10 +373,11 @@ static void get_service_config()
*/
sprintf_s(service_properties.inifile, MAX_PATH, "%s\\my.ini", service_properties.datadir);
}
sprintf(defaults_file_param, "--defaults-file=%s", service_properties.inifile);
snprintf(defaults_file_param, sizeof(defaults_file_param),
"--defaults-file=%s", service_properties.inifile);
}
/*
Change service configuration (binPath) to point to mysqld from
Change service configuration (binPath) to point to mysqld from
this installation.
*/
static void change_service_config()
@@ -407,7 +408,8 @@ static void change_service_config()
*/
WritePrivateProfileString("mysqld", "basedir",NULL, service_properties.inifile);
sprintf(defaults_file_param,"--defaults-file=%s", service_properties.inifile);
snprintf(defaults_file_param, sizeof(defaults_file_param),
"--defaults-file=%s", service_properties.inifile);
sprintf_s(commandline, "\"%s\" \"%s\" \"%s\"", mysqld_path,
defaults_file_param, opt_service);
if (!ChangeServiceConfig(service, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE,

View File

@@ -2474,8 +2474,8 @@ static void activate_tcp_port(uint port,
{
char buff[100];
int s_errno= socket_errno;
sprintf(buff, "Can't start server: Bind on TCP/IP port. Got error: %d",
(int) s_errno);
snprintf(buff, sizeof(buff), "Can't start server: Bind on TCP/IP port. Got error: %d",
(int) s_errno);
sql_perror(buff);
/*
Linux will quite happily bind to addresses not present. The
@@ -7029,7 +7029,8 @@ static int show_heartbeat_period(THD *thd, SHOW_VAR *var, void *buff,
get_master_info(&thd->variables.default_master_connection,
Sql_condition::WARN_LEVEL_NOTE))
{
sprintf(static_cast<char*>(buff), "%.3f", mi->heartbeat_period);
snprintf(static_cast<char*>(buff), SHOW_VAR_FUNC_BUFF_SIZE, "%.3f",
mi->heartbeat_period);
mi->release();
var->type= SHOW_CHAR;
var->value= buff;

View File

@@ -4598,13 +4598,14 @@ SJ_TMP_TABLE::create_sj_weedout_tmp_table(THD *thd)
temp_pool_slot = temp_pool_set_next();
if (temp_pool_slot != MY_BIT_NONE) // we got a slot
sprintf(path, "%s-subquery-%lx-%i", tmp_file_prefix,
current_pid, temp_pool_slot);
snprintf(path, sizeof(path), "%s-subquery-%lx-%i", tmp_file_prefix,
current_pid, temp_pool_slot);
else
{
/* if we run out of slots or we are not using tempool */
sprintf(path,"%s-subquery-%lx-%lx-%x", tmp_file_prefix,current_pid,
(ulong) thd->thread_id, thd->tmp_table++);
snprintf(path, sizeof(path), "%s-subquery-%lx-%lx-%x",
tmp_file_prefix, current_pid,
(ulong) thd->thread_id, thd->tmp_table++);
}
fn_format(path, path, mysql_tmpdir, "", MY_REPLACE_EXT|MY_UNPACK_FILENAME);

View File

@@ -122,7 +122,8 @@ void my_make_scrambled_password_323(char *to, const char *password,
{
ulong hash_res[2];
hash_password(hash_res, password, (uint) pass_len);
sprintf(to, "%08lx%08lx", hash_res[0], hash_res[1]);
snprintf(to, SCRAMBLED_PASSWORD_CHAR_LENGTH_323 + 1,
"%08lx%08lx", hash_res[0], hash_res[1]);
}
@@ -270,7 +271,8 @@ void get_salt_from_password_323(ulong *res, const char *password)
void make_password_from_salt_323(char *to, const ulong *salt)
{
sprintf(to,"%08lx%08lx", salt[0], salt[1]);
snprintf(to, SCRAMBLED_PASSWORD_CHAR_LENGTH_323 + 1,
"%08lx%08lx", salt[0], salt[1]);
}

View File

@@ -2153,7 +2153,7 @@ end:
const char*
rpl_binlog_state::drop_domain(DYNAMIC_ARRAY *ids,
Gtid_list_log_event *glev,
char* errbuf)
char* errbuf, size_t errbuf_size)
{
DYNAMIC_ARRAY domain_unique; // sequece (unsorted) of unique element*:s
rpl_binlog_state::element* domain_unique_buffer[16];
@@ -2189,21 +2189,21 @@ rpl_binlog_state::drop_domain(DYNAMIC_ARRAY *ids,
rpl_gtid* rb_state_gtid= find_nolock(glev->list[l].domain_id,
glev->list[l].server_id);
if (!rb_state_gtid)
sprintf(errbuf,
"missing gtids from the '%u-%u' domain-server pair which is "
"referred to in the gtid list describing an earlier state. Ignore "
"if the domain ('%u') was already explicitly deleted",
glev->list[l].domain_id, glev->list[l].server_id,
glev->list[l].domain_id);
snprintf(errbuf, errbuf_size,
"missing gtids from the '%u-%u' domain-server pair which is "
"referred to in the gtid list describing an earlier state. Ignore "
"if the domain ('%u') was already explicitly deleted",
glev->list[l].domain_id, glev->list[l].server_id,
glev->list[l].domain_id);
else if (rb_state_gtid->seq_no < glev->list[l].seq_no)
sprintf(errbuf,
"having a gtid '%u-%u-%llu' which is less than "
"the '%u-%u-%llu' of the gtid list describing an earlier state. "
"The state may have been affected by manually injecting "
"a lower sequence number gtid or via replication",
rb_state_gtid->domain_id, rb_state_gtid->server_id,
rb_state_gtid->seq_no, glev->list[l].domain_id,
glev->list[l].server_id, glev->list[l].seq_no);
snprintf(errbuf, errbuf_size,
"having a gtid '%u-%u-%llu' which is less than "
"the '%u-%u-%llu' of the gtid list describing an earlier state. "
"The state may have been affected by manually injecting "
"a lower sequence number gtid or via replication",
rb_state_gtid->domain_id, rb_state_gtid->server_id,
rb_state_gtid->seq_no, glev->list[l].domain_id,
glev->list[l].server_id, glev->list[l].seq_no);
if (strlen(errbuf)) // use strlen() as cheap flag
push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
ER_BINLOG_CANT_DELETE_GTID_DOMAIN,
@@ -2250,9 +2250,10 @@ rpl_binlog_state::drop_domain(DYNAMIC_ARRAY *ids,
if (!all_found)
{
sprintf(errbuf, "binlog files may contain gtids from the domain ('%u') "
"being deleted. Make sure to first purge those files",
*ptr_domain_id);
snprintf(errbuf, errbuf_size,
"binlog files may contain gtids from the domain ('%u') "
"being deleted. Make sure to first purge those files",
*ptr_domain_id);
errmsg= errbuf;
goto end;
}

View File

@@ -345,7 +345,8 @@ struct rpl_binlog_state
rpl_gtid *find_nolock(uint32 domain_id, uint32 server_id);
rpl_gtid *find(uint32 domain_id, uint32 server_id);
rpl_gtid *find_most_recent(uint32 domain_id);
const char* drop_domain(DYNAMIC_ARRAY *ids, Gtid_list_log_event *glev, char*);
const char* drop_domain(DYNAMIC_ARRAY *ids, Gtid_list_log_event *glev,
char*, size_t errbuf_size);
};

View File

@@ -761,19 +761,21 @@ int flush_master_info(Master_info* mi,
*/
char* ignore_server_ids_buf;
{
size_t ignore_buf_size=
(sizeof(global_system_variables.server_id) * 3 + 1) *
(1 + mi->ignore_server_ids.elements);
ignore_server_ids_buf=
(char *) my_malloc(PSI_INSTRUMENT_ME,
(sizeof(global_system_variables.server_id) * 3 + 1) *
(1 + mi->ignore_server_ids.elements), MYF(MY_WME));
(char *) my_malloc(PSI_INSTRUMENT_ME, ignore_buf_size, MYF(MY_WME));
if (!ignore_server_ids_buf)
DBUG_RETURN(1); /* error */
ulong cur_len= sprintf(ignore_server_ids_buf, "%zu",
mi->ignore_server_ids.elements);
ulong cur_len= snprintf(ignore_server_ids_buf, ignore_buf_size,
"%zu", mi->ignore_server_ids.elements);
for (ulong i= 0; i < mi->ignore_server_ids.elements; i++)
{
ulong s_id;
get_dynamic(&mi->ignore_server_ids, (uchar*) &s_id, i);
cur_len+= sprintf(ignore_server_ids_buf + cur_len, " %lu", s_id);
cur_len+= snprintf(ignore_server_ids_buf + cur_len,
ignore_buf_size - cur_len, " %lu", s_id);
}
}
@@ -1950,7 +1952,7 @@ char *Domain_id_filter::as_string(enum_list_type type)
return NULL;
// Store the total number of elements followed by the individual elements.
size_t cur_len= sprintf(buf, "%zu", ids->elements);
size_t cur_len= snprintf(buf, sz, "%zu", ids->elements);
sz-= cur_len;
for (uint i= 0; i < ids->elements; i++)
@@ -2004,17 +2006,17 @@ void prot_store_ids(THD *thd, DYNAMIC_ARRAY *ids)
ulong id, len;
char dbuff[FN_REFLEN];
get_dynamic(ids, (void *) &id, i);
len= sprintf(dbuff, (i == 0 ? "%lu" : ", %lu"), id);
len= snprintf(dbuff, sizeof(dbuff), (i == 0 ? "%lu" : ", %lu"), id);
if (cur_len + len + 4 > FN_REFLEN)
{
/*
break the loop whenever remained space could not fit
ellipses on the next cycle
*/
cur_len+= sprintf(dbuff + cur_len, "...");
cur_len+= snprintf(buff + cur_len, sizeof(buff) - cur_len, "...");
break;
}
cur_len+= sprintf(buff + cur_len, "%s", dbuff);
cur_len+= snprintf(buff + cur_len, sizeof(buff) - cur_len, "%s", dbuff);
}
thd->protocol->store(buff, cur_len, &my_charset_bin);
return;

View File

@@ -1924,7 +1924,7 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi)
"Master reported unrecognized MariaDB version: %s",
mysql->server_version);
err_code= ER_SLAVE_FATAL_ERROR;
sprintf(err_buff, ER_DEFAULT(err_code), err_buff2);
snprintf(err_buff, sizeof(err_buff), ER_DEFAULT(err_code), err_buff2);
}
else
{
@@ -1943,7 +1943,7 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi)
"Master reported unrecognized MariaDB version: %s",
mysql->server_version);
err_code= ER_SLAVE_FATAL_ERROR;
sprintf(err_buff, ER_DEFAULT(err_code), err_buff2);
snprintf(err_buff, sizeof(err_buff), ER_DEFAULT(err_code), err_buff2);
break;
case 3:
mi->rli.relay_log.description_event_for_queue= new
@@ -1983,7 +1983,7 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi)
{
errmsg= "default Format_description_log_event";
err_code= ER_SLAVE_CREATE_EVENT_FAILURE;
sprintf(err_buff, ER_DEFAULT(err_code), errmsg);
snprintf(err_buff, sizeof(err_buff), ER_DEFAULT(err_code), errmsg);
goto err;
}
@@ -2120,7 +2120,7 @@ MariaDB server ids; these ids must be different for replication to work (or \
the --replicate-same-server-id option must be used on slave but this does \
not always make sense; please check the manual before using it).";
err_code= ER_SLAVE_FATAL_ERROR;
sprintf(err_buff, ER_DEFAULT(err_code), errmsg);
snprintf(err_buff, sizeof(err_buff), ER_DEFAULT(err_code), errmsg);
goto err;
}
}
@@ -2138,7 +2138,7 @@ not always make sense; please check the manual before using it).";
errmsg= "The slave I/O thread stops because a fatal error is encountered \
when it try to get the value of SERVER_ID variable from master.";
err_code= mysql_errno(mysql);
sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql));
snprintf(err_buff, sizeof(err_buff), "%s Error: %s", errmsg, mysql_error(mysql));
goto err;
}
else if (!master_row && master_res)
@@ -2156,7 +2156,7 @@ maybe it is a *VERY OLD MASTER*.");
{
errmsg= "Slave configured with server id filtering could not detect the master server id.";
err_code= ER_SLAVE_FATAL_ERROR;
sprintf(err_buff, ER_DEFAULT(err_code), errmsg);
snprintf(err_buff, sizeof(err_buff), ER_DEFAULT(err_code), errmsg);
goto err;
}
@@ -2196,7 +2196,7 @@ maybe it is a *VERY OLD MASTER*.");
different values for the COLLATION_SERVER global variable. The values must \
be equal for the Statement-format replication to work";
err_code= ER_SLAVE_FATAL_ERROR;
sprintf(err_buff, ER_DEFAULT(err_code), errmsg);
snprintf(err_buff, sizeof(err_buff), ER_DEFAULT(err_code), errmsg);
goto err;
}
}
@@ -2214,7 +2214,7 @@ be equal for the Statement-format replication to work";
errmsg= "The slave I/O thread stops because a fatal error is encountered \
when it try to get the value of COLLATION_SERVER global variable from master.";
err_code= mysql_errno(mysql);
sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql));
snprintf(err_buff, sizeof(err_buff), "%s Error: %s", errmsg, mysql_error(mysql));
goto err;
}
else
@@ -2259,7 +2259,7 @@ inconsistency if replicated data deals with collation.");
different values for the TIME_ZONE global variable. The values must \
be equal for the Statement-format replication to work";
err_code= ER_SLAVE_FATAL_ERROR;
sprintf(err_buff, ER_DEFAULT(err_code), errmsg);
snprintf(err_buff, sizeof(err_buff), ER_DEFAULT(err_code), errmsg);
goto err;
}
}
@@ -2286,7 +2286,7 @@ be equal for the Statement-format replication to work";
/* Fatal error */
errmsg= "The slave I/O thread stops because a fatal error is encountered \
when it try to get the value of TIME_ZONE global variable from master.";
sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql));
snprintf(err_buff, sizeof(err_buff), "%s Error: %s", errmsg, mysql_error(mysql));
goto err;
}
if (master_res)
@@ -2331,7 +2331,7 @@ when it try to get the value of TIME_ZONE global variable from master.";
errmsg= "The slave I/O thread stops because a fatal error is encountered "
"when it tries to SET @master_heartbeat_period on master.";
err_code= ER_SLAVE_FATAL_ERROR;
sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql));
snprintf(err_buff, sizeof(err_buff), "%s Error: %s", errmsg, mysql_error(mysql));
mysql_free_result(mysql_store_result(mysql));
goto err;
}
@@ -2391,7 +2391,7 @@ when it try to get the value of TIME_ZONE global variable from master.";
errmsg= "The slave I/O thread stops because a fatal error is encountered "
"when it tried to SET @master_binlog_checksum on master.";
err_code= ER_SLAVE_FATAL_ERROR;
sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql));
snprintf(err_buff, sizeof(err_buff), "%s Error: %s", errmsg, mysql_error(mysql));
mysql_free_result(mysql_store_result(mysql));
goto err;
}
@@ -2425,7 +2425,7 @@ when it try to get the value of TIME_ZONE global variable from master.";
errmsg= "The slave I/O thread stops because a fatal error is encountered "
"when it tried to SELECT @master_binlog_checksum.";
err_code= ER_SLAVE_FATAL_ERROR;
sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql));
snprintf(err_buff, sizeof(err_buff), "%s Error: %s", errmsg, mysql_error(mysql));
mysql_free_result(mysql_store_result(mysql));
goto err;
}
@@ -2482,7 +2482,7 @@ past_checksum:
errmsg= "The slave I/O thread stops because a fatal error is "
"encountered when it tries to request filtering of events marked "
"with the @@skip_replication flag.";
sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql));
snprintf(err_buff, sizeof(err_buff), "%s Error: %s", errmsg, mysql_error(mysql));
goto err;
}
}
@@ -2514,7 +2514,7 @@ past_checksum:
/* Fatal error */
errmsg= "The slave I/O thread stops because a fatal error is "
"encountered when it tries to set @mariadb_slave_capability.";
sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql));
snprintf(err_buff, sizeof(err_buff), "%s Error: %s", errmsg, mysql_error(mysql));
goto err;
}
}
@@ -2566,7 +2566,7 @@ after_set_capability:
errmsg= "The slave I/O thread stops because master does not support "
"MariaDB global transaction id. A fatal error is encountered when "
"it tries to SELECT @@GLOBAL.gtid_domain_id.";
sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql));
snprintf(err_buff, sizeof(err_buff), "%s Error: %s", errmsg, mysql_error(mysql));
goto err;
}
}
@@ -2580,7 +2580,7 @@ after_set_capability:
err_code= ER_OUTOFMEMORY;
errmsg= "The slave I/O thread stops because a fatal out-of-memory "
"error is encountered when it tries to compute @slave_connect_state.";
sprintf(err_buff, "%s Error: Out of memory", errmsg);
snprintf(err_buff, sizeof(err_buff), "%s Error: Out of memory", errmsg);
goto err;
}
query_str.append(STRING_WITH_LEN("'"), system_charset_info);
@@ -2604,7 +2604,7 @@ after_set_capability:
/* Fatal error */
errmsg= "The slave I/O thread stops because a fatal error is "
"encountered when it tries to set @slave_connect_state.";
sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql));
snprintf(err_buff, sizeof(err_buff), "%s Error: %s", errmsg, mysql_error(mysql));
goto err;
}
}
@@ -2617,7 +2617,7 @@ after_set_capability:
err_code= ER_OUTOFMEMORY;
errmsg= "The slave I/O thread stops because a fatal out-of-memory "
"error is encountered when it tries to set @slave_gtid_strict_mode.";
sprintf(err_buff, "%s Error: Out of memory", errmsg);
snprintf(err_buff, sizeof(err_buff), "%s Error: Out of memory", errmsg);
goto err;
}
@@ -2640,7 +2640,7 @@ after_set_capability:
/* Fatal error */
errmsg= "The slave I/O thread stops because a fatal error is "
"encountered when it tries to set @slave_gtid_strict_mode.";
sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql));
snprintf(err_buff, sizeof(err_buff), "%s Error: %s", errmsg, mysql_error(mysql));
goto err;
}
}
@@ -2653,7 +2653,7 @@ after_set_capability:
err_code= ER_OUTOFMEMORY;
errmsg= "The slave I/O thread stops because a fatal out-of-memory error "
"is encountered when it tries to set @slave_gtid_ignore_duplicates.";
sprintf(err_buff, "%s Error: Out of memory", errmsg);
snprintf(err_buff, sizeof(err_buff), "%s Error: Out of memory", errmsg);
goto err;
}
@@ -2676,7 +2676,7 @@ after_set_capability:
/* Fatal error */
errmsg= "The slave I/O thread stops because a fatal error is "
"encountered when it tries to set @slave_gtid_ignore_duplicates.";
sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql));
snprintf(err_buff, sizeof(err_buff), "%s Error: %s", errmsg, mysql_error(mysql));
goto err;
}
}
@@ -2691,7 +2691,7 @@ after_set_capability:
err_code= ER_OUTOFMEMORY;
errmsg= "The slave I/O thread stops because a fatal out-of-memory "
"error is encountered when it tries to compute @slave_until_gtid.";
sprintf(err_buff, "%s Error: Out of memory", errmsg);
snprintf(err_buff, sizeof(err_buff), "%s Error: Out of memory", errmsg);
goto err;
}
query_str.append(STRING_WITH_LEN("'"), system_charset_info);
@@ -2715,7 +2715,7 @@ after_set_capability:
/* Fatal error */
errmsg= "The slave I/O thread stops because a fatal error is "
"encountered when it tries to set @slave_until_gtid.";
sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql));
snprintf(err_buff, sizeof(err_buff), "%s Error: %s", errmsg, mysql_error(mysql));
goto err;
}
}

View File

@@ -4302,8 +4302,8 @@ bool change_password(THD *thd, LEX_USER *user)
result= acl_cache_is_locked= 0;
if (mysql_bin_log.is_open())
{
query_length= sprintf(buff, "SET PASSWORD FOR '%-.120s'@'%-.120s'='%-.120s'",
user->user.str, safe_str(user->host.str), auth.auth_string.str);
query_length= snprintf(buff, sizeof(buff), "SET PASSWORD FOR '%-.120s'@'%-.120s'='%-.120s'",
user->user.str, safe_str(user->host.str), auth.auth_string.str);
DBUG_ASSERT(query_length);
thd->clear_error();
result= thd->binlog_query(THD::STMT_QUERY_TYPE, buff, query_length,
@@ -4370,8 +4370,8 @@ int acl_set_default_role(THD *thd, const char *host, const char *user,
(WSREP(thd) && !IF_WSREP(thd->wsrep_applier, 0)))
{
query_length=
sprintf(buff,"SET DEFAULT ROLE '%-.120s' FOR '%-.120s'@'%-.120s'",
safe_str(rolename), user, safe_str(host));
snprintf(buff, sizeof(buff), "SET DEFAULT ROLE '%-.120s' FOR '%-.120s'@'%-.120s'",
safe_str(rolename), user, safe_str(host));
}
/*

View File

@@ -7751,11 +7751,11 @@ static void reset_binlog_unsafe_suppression(ulonglong now)
Auxiliary function to print warning in the error log.
*/
static void print_unsafe_warning_to_log(THD *thd, int unsafe_type, char* buf,
char* query)
size_t buf_size, char* query)
{
DBUG_ENTER("print_unsafe_warning_in_log");
sprintf(buf, ER_THD(thd, ER_BINLOG_UNSAFE_STATEMENT),
ER_THD(thd, LEX::binlog_stmt_unsafe_errcode[unsafe_type]));
snprintf(buf, buf_size, ER_THD(thd, ER_BINLOG_UNSAFE_STATEMENT),
ER_THD(thd, LEX::binlog_stmt_unsafe_errcode[unsafe_type]));
sql_print_warning(ER_THD(thd, ER_MESSAGE_AND_STATEMENT), buf, query);
DBUG_VOID_RETURN;
}
@@ -7897,7 +7897,8 @@ void THD::issue_unsafe_warnings()
ER_THD(this, LEX::binlog_stmt_unsafe_errcode[unsafe_type]));
if (global_system_variables.log_warnings > 0 &&
!protect_against_unsafe_warning_flood(unsafe_type))
print_unsafe_warning_to_log(this, unsafe_type, buf, query());
print_unsafe_warning_to_log(this, unsafe_type, buf,
sizeof(buf), query());
}
}
DBUG_VOID_RETURN;

View File

@@ -1430,14 +1430,14 @@ values_loop_end:
info.touched : info.updated);
if (ignore)
sprintf(buff, ER_THD(thd, ER_INSERT_INFO), (ulong) info.records,
(lock_type == TL_WRITE_DELAYED) ? (ulong) 0 :
(ulong) (info.records - info.copied),
(long) thd->get_stmt_da()->current_statement_warn_count());
snprintf(buff, sizeof(buff), ER_THD(thd, ER_INSERT_INFO), (ulong) info.records,
(lock_type == TL_WRITE_DELAYED) ? (ulong) 0 :
(ulong) (info.records - info.copied),
(long) thd->get_stmt_da()->current_statement_warn_count());
else
sprintf(buff, ER_THD(thd, ER_INSERT_INFO), (ulong) info.records,
(ulong) (info.deleted + updated),
(long) thd->get_stmt_da()->current_statement_warn_count());
snprintf(buff, sizeof(buff), ER_THD(thd, ER_INSERT_INFO), (ulong) info.records,
(ulong) (info.deleted + updated),
(long) thd->get_stmt_da()->current_statement_warn_count());
if (returning)
result->send_eof();
else if (!(thd->in_sub_stmt & SUB_STMT_TRIGGER))

View File

@@ -796,10 +796,10 @@ int mysql_load(THD *thd, const sql_exchange *ex, TABLE_LIST *table_list,
error= -1; // Error on read
goto err;
}
sprintf(name, ER_THD(thd, ER_LOAD_INFO),
(ulong) info.records, (ulong) info.deleted,
(ulong) (info.records - info.copied),
(long) thd->get_stmt_da()->current_statement_warn_count());
snprintf(name, sizeof(name), ER_THD(thd, ER_LOAD_INFO),
(ulong) info.records, (ulong) info.deleted,
(ulong) (info.records - info.copied),
(long) thd->get_stmt_da()->current_statement_warn_count());
if (thd->transaction->stmt.modified_non_trans_table)
thd->transaction->all.modified_non_trans_table= TRUE;

View File

@@ -3969,8 +3969,9 @@ void mysql_stmt_get_longdata(THD *thd, char *packet, ulong packet_length)
/* Error will be sent in execute call */
stmt->state= Query_arena::STMT_ERROR;
stmt->last_errno= ER_WRONG_ARGUMENTS;
sprintf(stmt->last_error, ER_THD(thd, ER_WRONG_ARGUMENTS),
"mysqld_stmt_send_long_data");
snprintf(stmt->last_error, sizeof(stmt->last_error),
ER_THD(thd, ER_WRONG_ARGUMENTS),
"mysqld_stmt_send_long_data");
DBUG_VOID_RETURN;
}
#endif

View File

@@ -20672,13 +20672,14 @@ TABLE *Create_tmp_table::start(THD *thd,
m_temp_pool_slot = temp_pool_set_next();
if (m_temp_pool_slot != MY_BIT_NONE) // we got a slot
sprintf(path, "%s-%s-%lx-%i", tmp_file_prefix, param->tmp_name,
current_pid, m_temp_pool_slot);
snprintf(path, sizeof(path), "%s-%s-%lx-%i", tmp_file_prefix, param->tmp_name,
current_pid, m_temp_pool_slot);
else
{
/* if we run out of slots or we are not using tempool */
sprintf(path, "%s-%s-%lx-%llx-%x", tmp_file_prefix, param->tmp_name,
current_pid, thd->thread_id, thd->tmp_table++);
snprintf(path, sizeof(path), "%s-%s-%lx-%llx-%x",
tmp_file_prefix, param->tmp_name,
current_pid, thd->thread_id, thd->tmp_table++);
}
/*

View File

@@ -588,7 +588,7 @@ bool Item_func_in::create_value_list_for_tvc(THD *thd,
{
if (i == 1)
{
sprintf(col_name, "_col_%i", j+1);
snprintf(col_name, sizeof(col_name), "_col_%i", j+1);
row_list->element_index(j)->set_name(thd, col_name, strlen(col_name),
thd->charset());
}
@@ -601,7 +601,7 @@ bool Item_func_in::create_value_list_for_tvc(THD *thd,
{
if (i == 1)
{
sprintf(col_name, "_col_%i", 1);
snprintf(col_name, sizeof(col_name), "_col_%i", 1);
args[i]->set_name(thd, col_name, strlen(col_name), thd->charset());
}
if (tvc_value->push_back(args[i]))

View File

@@ -39,8 +39,6 @@
#include "debug.h" // debug_crash_here
#include "wsrep_mysqld.h"
#define MD5_BUFF_LENGTH 33
const LEX_CSTRING view_type= { STRING_WITH_LEN("VIEW") };
static int mysql_register_view(THD *thd, DDL_LOG_STATE *ddl_log_state,
@@ -909,7 +907,7 @@ int mariadb_fix_view(THD *thd, TABLE_LIST *view, bool wrong_checksum,
{
if (view->md5.length != VIEW_MD5_LEN)
{
if ((view->md5.str= (char *)thd->alloc(VIEW_MD5_LEN + 1)) == NULL)
if ((view->md5.str= (char *)thd->alloc(MD5_BUFF_LENGTH)) == NULL)
DBUG_RETURN(HA_ADMIN_FAILED);
}
view->calc_md5(const_cast<char*>(view->md5.str));

View File

@@ -5957,7 +5957,7 @@ TABLE_LIST::TABLE_LIST(THD *thd,
SYNOPSIS
TABLE_LIST::calc_md5()
buffer buffer for md5 writing
buffer buffer for md5 writing, must be at least MD5_BUFF_LENGTH bytes
*/
void TABLE_LIST::calc_md5(char *buffer)
@@ -5965,12 +5965,12 @@ void TABLE_LIST::calc_md5(char *buffer)
uchar digest[16];
compute_md5_hash(digest, select_stmt.str,
select_stmt.length);
sprintf(buffer,
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
digest[0], digest[1], digest[2], digest[3],
digest[4], digest[5], digest[6], digest[7],
digest[8], digest[9], digest[10], digest[11],
digest[12], digest[13], digest[14], digest[15]);
snprintf(buffer, MD5_BUFF_LENGTH,
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
digest[0], digest[1], digest[2], digest[3],
digest[4], digest[5], digest[6], digest[7],
digest[8], digest[9], digest[10], digest[11],
digest[12], digest[13], digest[14], digest[15]);
}
@@ -8525,8 +8525,7 @@ bool TABLE::add_tmp_key(uint key, uint key_parts,
keyinfo->is_statistics_from_stat_tables= FALSE;
if (unique)
keyinfo->flags|= HA_NOSAME;
sprintf(buf, "key%i", key);
keyinfo->name.length= strlen(buf);
keyinfo->name.length= snprintf(buf, sizeof(buf), "key%i", key);
if (!(keyinfo->name.str= strmake_root(&mem_root, buf, keyinfo->name.length)))
return TRUE;
keyinfo->rec_per_key= (ulong*) alloc_root(&mem_root,

View File

@@ -90,6 +90,7 @@ class Open_table_context;
typedef ulonglong nested_join_map;
#define VIEW_MD5_LEN 32
#define MD5_BUFF_LENGTH (VIEW_MD5_LEN + 1) /* hex digest + NUL */
#define tmp_file_prefix "#sql" /**< Prefix for tmp tables */
@@ -2835,6 +2836,7 @@ struct TABLE_LIST
List<String> *partition_names;
#endif /* WITH_PARTITION_STORAGE_ENGINE */
/* buffer must be at least MD5_BUFF_LENGTH bytes long */
void calc_md5(char *buffer);
int view_check_option(THD *thd, bool ignore_failure);
bool create_field_translation(THD *thd);

View File

@@ -849,11 +849,11 @@ char *reverse_lookup(UDF_INIT *initid __attribute__((unused)), UDF_ARGS *args,
*null_value=1;
return 0;
}
sprintf(result,"%d.%d.%d.%d",
(int) *((longlong*) args->args[0]),
(int) *((longlong*) args->args[1]),
(int) *((longlong*) args->args[2]),
(int) *((longlong*) args->args[3]));
snprintf(result, MYSQL_UDF_MAX_RESULT_LENGTH, "%d.%d.%d.%d",
(int) *((longlong*) args->args[0]),
(int) *((longlong*) args->args[1]),
(int) *((longlong*) args->args[2]),
(int) *((longlong*) args->args[3]));
}
else
{ /* string argument */
@@ -1245,9 +1245,9 @@ char * is_const(UDF_INIT *initid, UDF_ARGS *args __attribute__((unused)),
uchar *is_null,uchar *error __attribute__((unused)))
{
if (initid->ptr != 0) {
sprintf(result, "const");
snprintf(result, MYSQL_UDF_MAX_RESULT_LENGTH, "const");
} else {
sprintf(result, "not const");
snprintf(result, MYSQL_UDF_MAX_RESULT_LENGTH, "not const");
}
*is_null= 0;
*length= (uint) strlen(result);

View File

@@ -100,8 +100,8 @@ static void wsrep_store_error_rli(const THD* const thd,
}
os << " Error_code: " << error.number << ';';
std::string const err_str= os.str();
dst.resize(err_str.length() + 1);
sprintf(dst.data(), "%s", err_str.c_str());
dst.clear();
dst.push_back(err_str);
WSREP_DEBUG("Error buffer (RLI) for thd %u seqno %lld, %zu bytes: '%s'",
thd->thread_id, (long long)wsrep_thd_trx_seqno(thd),

View File

@@ -1793,9 +1793,9 @@ static int sst_flush_tables(THD* thd)
const char base_name[]= "tables_flushed";
ssize_t const full_len= strlen(mysql_real_data_home) + strlen(base_name)+2;
char *real_name= (char*) my_malloc(key_memory_WSREP, full_len, 0);
sprintf(real_name, "%s/%s", mysql_real_data_home, base_name);
snprintf(real_name, full_len, "%s/%s", mysql_real_data_home, base_name);
char *tmp_name= (char*) my_malloc(key_memory_WSREP, full_len + 4, 0);
sprintf(tmp_name, "%s.tmp", real_name);
snprintf(tmp_name, full_len + 4, "%s.tmp", real_name);
FILE* file= fopen(tmp_name, "w+");
if (0 == file)

View File

@@ -1024,7 +1024,7 @@ void ARRAY::Prints(PGLOBAL, char *ps, uint z)
if (z < 16)
return;
sprintf(ps, "ARRAY: type=%d\n", Type);
snprintf(ps, z, "ARRAY: type=%d\n", Type);
// More to be implemented later
} // end of Prints

View File

@@ -1547,16 +1547,16 @@ PSZ BJSON::GetString(PBVAL vp, char* buff)
p = MZP(vlp->To_Val);
break;
case TYPE_INTG:
sprintf(p, "%d", vlp->N);
snprintf(p, 32, "%d", vlp->N);
break;
case TYPE_FLOAT:
sprintf(p, "%.*f", vlp->Nd, vlp->F);
snprintf(p, 32, "%.*f", vlp->Nd, vlp->F);
break;
case TYPE_BINT:
sprintf(p, "%lld", *(longlong*)MP(vlp->To_Val));
snprintf(p, 32, "%lld", *(longlong*)MP(vlp->To_Val));
break;
case TYPE_DBL:
sprintf(p, "%.*lf", vlp->Nd, *(double*)MP(vlp->To_Val));
snprintf(p, 32, "%.*lf", vlp->Nd, *(double*)MP(vlp->To_Val));
break;
case TYPE_BOOL:
p = (PSZ)((vlp->B) ? "true" : "false");

View File

@@ -3541,7 +3541,7 @@ my_bool bson_item_merge_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
return true;
} else for (int i = 0; i < 2; i++)
if (!IsArgJson(args, i) && args->arg_type[i] != STRING_RESULT) {
sprintf(message, "Argument %d must be a json item", i);
snprintf(message, MYSQL_ERRMSG_SIZE, "Argument %d must be a json item", i);
return true;
} // endif type
@@ -4433,7 +4433,7 @@ my_bool bson_file_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
for (unsigned int i = 1; i < args->arg_count; i++) {
if (!(args->arg_type[i] == INT_RESULT || args->arg_type[i] == STRING_RESULT)) {
sprintf(message, "Argument %d is not an integer or a string (pretty or path)", i);
snprintf(message, MYSQL_ERRMSG_SIZE, "Argument %d is not an integer or a string (pretty or path)", i);
return true;
} // endif arg_type
@@ -4669,7 +4669,7 @@ my_bool bfile_convert_init(UDF_INIT* initid, UDF_ARGS* args, char* message) {
return true;
} else for (int i = 0; i < 2; i++)
if (args->arg_type[i] != STRING_RESULT) {
sprintf(message, "Arguments %d must be a string (file name)", i+1);
snprintf(message, MYSQL_ERRMSG_SIZE, "Arguments %d must be a string (file name)", i+1);
return true;
} // endif args
@@ -4726,7 +4726,7 @@ my_bool bfile_bjson_init(UDF_INIT* initid, UDF_ARGS* args, char* message) {
return true;
} else for (int i = 0; i < 2; i++)
if (args->arg_type[i] != STRING_RESULT) {
sprintf(message, "Arguments %d must be a string (file name)", i + 1);
snprintf(message, MYSQL_ERRMSG_SIZE, "Arguments %d must be a string (file name)", i + 1);
return true;
} // endif args

View File

@@ -867,7 +867,7 @@ char *CMgoConn::Mini(PGLOBAL g, PCOL colp, const bson_t *bson, bool b)
} else if (dbl && n > m) {
Mbuf[k] = 0;
d = atof(Mbuf + j);
n = sprintf(Mbuf + j, "%.*f", m, d);
n = snprintf(Mbuf + j, (size_t)colp->GetLength() + 1 - j, "%.*f", m, d);
k = j + n;
j = n = 0;
} else if (j)
@@ -1019,7 +1019,7 @@ bool CMgoConn::AddValue(PGLOBAL g, PCOL colp, bson_t *doc, char *key, bool upd)
bson_t *bsn = bson_new_from_json(val, -1, &Error);
if (!bsn) {
sprintf (g->Message, "AddValue: %s", Error.message);
snprintf(g->Message, sizeof(g->Message), "AddValue: %s", Error.message);
return true;
} else if (*key) {
if (*val == '[')

View File

@@ -237,9 +237,9 @@ void COLBLK::Printf(PGLOBAL, FILE *f, uint n)
/***********************************************************************/
/* Make string output of a column descriptor block. */
/***********************************************************************/
void COLBLK::Prints(PGLOBAL, char *ps, uint)
void COLBLK::Prints(PGLOBAL, char *ps, uint z)
{
sprintf(ps, "R%d.%s", To_Tdb->GetTdb_No(), Name);
snprintf(ps, z, "R%d.%s", To_Tdb->GetTdb_No(), Name);
} // end of Prints

View File

@@ -118,7 +118,7 @@ int CSORT::Qsort(PGLOBAL g, int nb)
Dup->ProgMax = Cmpnum(nb);
Dup->ProgCur = 0;
Dup->Step = (char*)PlugSubAlloc(g, NULL, 32);
sprintf((char*)Dup->Step, MSG(SORTING_VAL), nb);
snprintf((char*)Dup->Step, 32, MSG(SORTING_VAL), nb);
} else
Dup = NULL;

View File

@@ -163,7 +163,7 @@ bool DOMDOC::NewDoc(PGLOBAL g, PCSZ ver)
char buf[64];
MSXML2::IXMLDOMProcessingInstructionPtr pip;
sprintf(buf, "version=\"%s\" encoding=\"%s\"", ver, Encoding);
snprintf(buf, sizeof(buf), "version=\"%s\" encoding=\"%s\"", ver, Encoding);
pip = Docp->createProcessingInstruction("xml", buf);
Docp->appendChild(pip);
return false;

View File

@@ -437,7 +437,7 @@ PQRYRES DBFColumns(PGLOBAL g, PCSZ dp, PCSZ fn, PTOS topt, bool info)
/************************************************************************/
char buf[64];
sprintf(buf,
snprintf(buf, sizeof(buf),
"Ver=%02x ncol=%hu nlin=%u lrecl=%hu headlen=%hu date=%02d/%02d/%02d",
hp->Version, fields, hp->Records, hp->Reclen,
hp->Headlen, hp->Filedate[0], hp->Filedate[1],

View File

@@ -5976,7 +5976,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
#if defined(REST_SUPPORT)
case TAB_REST:
if (!topt->http)
sprintf(g->Message, "Missing %s HTTP address", topt->type);
snprintf(g->Message, sizeof(g->Message), "Missing %s HTTP address", topt->type);
else
ok= true;

View File

@@ -1670,13 +1670,13 @@ PSZ JVALUE::GetString(PGLOBAL g, char *buff)
p = Strp;
break;
case TYPE_INTG:
sprintf(p, "%d", N);
snprintf(p, 32, "%d", N);
break;
case TYPE_BINT:
sprintf(p, "%lld", LLn);
snprintf(p, 32, "%lld", LLn);
break;
case TYPE_DBL:
sprintf(p, "%.*lf", Nd, F);
snprintf(p, 32, "%.*lf", Nd, F);
break;
case TYPE_BOOL:
p = (char*)((B) ? "true" : "false");

View File

@@ -4517,7 +4517,7 @@ my_bool json_file_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
for (unsigned int i = 1; i < args->arg_count; i++) {
if (!(args->arg_type[i] == INT_RESULT || args->arg_type[i] == STRING_RESULT)) {
sprintf(message, "Argument %d is not an integer or a string (pretty or path)", i);
snprintf(message, MYSQL_ERRMSG_SIZE, "Argument %d is not an integer or a string (pretty or path)", i);
return true;
} // endif arg_type
@@ -5774,7 +5774,7 @@ my_bool jbin_file_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
for (unsigned int i = 1; i < args->arg_count; i++) {
if (!(args->arg_type[i] == INT_RESULT || args->arg_type[i] == STRING_RESULT)) {
sprintf(message, "Argument %d is not an integer or a string (pretty or path)", i);
snprintf(message, MYSQL_ERRMSG_SIZE, "Argument %d is not an integer or a string (pretty or path)", i);
return true;
} // endif arg_type
@@ -5936,7 +5936,7 @@ my_bool jfile_convert_init(UDF_INIT* initid, UDF_ARGS* args, char* message) {
return true;
} else for (int i = 0; i < 2; i++)
if (args->arg_type[i] != STRING_RESULT) {
sprintf(message, "Arguments %d must be a string (file name)", i+1);
snprintf(message, MYSQL_ERRMSG_SIZE, "Arguments %d must be a string (file name)", i+1);
return true;
} // endif args
@@ -5993,7 +5993,7 @@ my_bool jfile_bjson_init(UDF_INIT* initid, UDF_ARGS* args, char* message) {
return true;
} else for (int i = 0; i < 2; i++)
if (args->arg_type[i] != STRING_RESULT) {
sprintf(message, "Arguments %d must be a string (file name)", i + 1);
snprintf(message, MYSQL_ERRMSG_SIZE, "Arguments %d must be a string (file name)", i + 1);
return true;
} // endif args

View File

@@ -195,7 +195,7 @@ void xtrc(char const *fmt, ...)
va_start (ap, fmt);
;
//vfprintf(stderr, fmt, ap);
vsprintf(s, fmt, ap);
vsnprintf(s, sizeof(s), fmt, ap);
if (s[strlen(s)-1] == '\n')
s[strlen(s)-1] = 0;
va_end (ap);

View File

@@ -248,7 +248,7 @@ bool MACINFO::GetOneInfo(PGLOBAL g, int flag, void *v, int lv)
if (i)
strcat(p++, "-");
p += sprintf(p, "%.2X", Curp->Address[i]);
p += snprintf(p, sizeof(buf) - (p - buf), "%.2X", Curp->Address[i]);
} // endfor i
p = buf;
@@ -263,7 +263,7 @@ bool MACINFO::GetOneInfo(PGLOBAL g, int flag, void *v, int lv)
case IF_LOOPBACK_ADAPTERTYPE: p = "Loop Back Adapter"; break;
// case IF_SLIP_ADAPTERTYPE: p = "Generic Slip Adapter"; break;
default:
sprintf(buf, "Other Adapter, type=%d", Curp->Type);
snprintf(buf, sizeof(buf), "Other Adapter, type=%d", Curp->Type);
p = buf;
} // endswitch Type
#endif // 0

View File

@@ -598,7 +598,7 @@ int MYSQLC::KillQuery(ulong id)
{
char kill[20];
sprintf(kill, "KILL QUERY %u", (unsigned int) id);
snprintf(kill, sizeof(kill), "KILL QUERY %u", (unsigned int) id);
//return (m_DB) ? mysql_query(m_DB, kill) : 1;
return (m_DB) ? mysql_real_query(m_DB, kill, strlen(kill)) : 1;
} // end of KillQuery
@@ -721,9 +721,10 @@ int MYSQLC::ExecSQL(PGLOBAL g, const char *query, int *w)
//if (mysql_query(m_DB, query) != 0) {
if (mysql_real_query(m_DB, query, strlen(query))) {
char *msg = (char*)PlugSubAlloc(g, NULL, 512 + strlen(query));
size_t msg_size = 512 + strlen(query);
char *msg = (char*)PlugSubAlloc(g, NULL, msg_size);
sprintf(msg, "(%d) %s [%s]", mysql_errno(m_DB),
snprintf(msg, msg_size, "(%d) %s [%s]", mysql_errno(m_DB),
mysql_error(m_DB), query);
strncpy(g->Message, msg, sizeof(g->Message) - 1);
g->Message[sizeof(g->Message) - 1] = 0;
@@ -740,9 +741,10 @@ int MYSQLC::ExecSQL(PGLOBAL g, const char *query, int *w)
m_Res = mysql_store_result(m_DB);
if (!m_Res) {
char *msg = (char*)PlugSubAlloc(g, NULL, 512 + strlen(query));
size_t msg_size = 512 + strlen(query);
char *msg = (char*)PlugSubAlloc(g, NULL, msg_size);
sprintf(msg, "mysql_store_result failed: %s", mysql_error(m_DB));
snprintf(msg, msg_size, "mysql_store_result failed: %s", mysql_error(m_DB));
strncpy(g->Message, msg, sizeof(g->Message) - 1);
g->Message[sizeof(g->Message) - 1] = 0;
rc = RC_FX;
@@ -777,9 +779,10 @@ int MYSQLC::GetTableSize(PGLOBAL g __attribute__((unused)), PSZ query)
{
if (mysql_real_query(m_DB, query, strlen(query))) {
#if defined(_DEBUG)
char *msg = (char*)PlugSubAlloc(g, NULL, 512 + strlen(query));
size_t msg_size = 512 + strlen(query);
char *msg = (char*)PlugSubAlloc(g, NULL, msg_size);
sprintf(msg, "(%d) %s [%s]", mysql_errno(m_DB),
snprintf(msg, msg_size, "(%d) %s [%s]", mysql_errno(m_DB),
mysql_error(m_DB), query);
strncpy(g->Message, msg, sizeof(g->Message) - 1);
g->Message[sizeof(g->Message) - 1] = 0;

View File

@@ -439,8 +439,9 @@ PQRYRES ODBCSrcCols(PGLOBAL g, char *dsn, char *src, POPARM sop)
if (strstr(src, "%s")) {
// Place holder for an eventual where clause
sqry = (char*)PlugSubAlloc(g, NULL, strlen(src) + 3);
sprintf(sqry, src, "1=1", "1=1"); // dummy where clause
size_t sqry_size = strlen(src) + 3;
sqry = (char*)PlugSubAlloc(g, NULL, sqry_size);
snprintf(sqry, sqry_size, src, "1=1", "1=1"); // dummy where clause
} else
sqry = src;

View File

@@ -1008,7 +1008,7 @@ bool WritePrivateProfileInt(LPCSTR sec, LPCSTR key, int n, LPCSTR ini)
{
char buf[12];
sprintf(buf, "%d", n);
snprintf(buf, sizeof(buf), "%d", n);
return WritePrivateProfileString(sec, key, buf, ini);
} // end of WritePrivateProfileInt
@@ -1115,7 +1115,7 @@ char *GetAmName(PGLOBAL g, AMT am, void *memp)
case TYPE_AM_MAC: strcpy(amn, "MAC"); break;
case TYPE_AM_OEM: strcpy(amn, "OEM"); break;
case TYPE_AM_OUT: strcpy(amn, "OUT"); break;
default: sprintf(amn, "OEM(%d)", am);
default: snprintf(amn, 16, "OEM(%d)", am);
} // endswitch am
return amn;

View File

@@ -48,11 +48,11 @@ int GetRcString(int id, char *buf, int bufsize)
char msg[32];
if (!(p = GetMsgid(id))) {
sprintf(msg, "ID=%d unknown", id);
snprintf(msg, sizeof(msg), "ID=%d unknown", id);
p = msg;
} // endif p
return sprintf(buf, "%.*s", bufsize-1, p);
return snprintf(buf, bufsize, "%.*s", bufsize-1, p);
} // end of GetRcString
#endif // !XMSG

View File

@@ -754,9 +754,9 @@ bool OEMDEF::DefineAM(PGLOBAL g, LPCSTR, int)
if (!*Module)
Module = Subtype;
char *desc = (char*)PlugSubAlloc(g, NULL, strlen(Module)
+ strlen(Subtype) + 3);
sprintf(desc, "%s(%s)", Module, Subtype);
size_t desc_size = strlen(Module) + strlen(Subtype) + 3;
char *desc = (char*)PlugSubAlloc(g, NULL, desc_size);
snprintf(desc, desc_size, "%s(%s)", Module, Subtype);
Desc = desc;
// If define block not here yet, get it now

View File

@@ -79,7 +79,7 @@ int restGetFile(char *m, bool xt, PCSZ http, PCSZ uri, PCSZ fn)
if (xt)
fprintf(stderr, "Error exception: %s\n", e.what());
sprintf(m, "Error exception: %s", e.what());
snprintf(m, 4160, "Error exception: %s", e.what());
rc= 1;
} // end try/catch

View File

@@ -99,7 +99,7 @@ void XTAB::Prints(PGLOBAL, char *ps, uint z)
*ps = '\0';
for (PTABLE tp = this; tp && n > 0; tp = tp->Next) {
i = sprintf(buf, "TABLE: %s.%s %s To_Tdb=%p ",
i = snprintf(buf, sizeof(buf), "TABLE: %s.%s %s To_Tdb=%p ",
SVP(tp->Schema), tp->Name, SVP(tp->Srcdef), tp->To_Tdb);
strncat(ps, buf, n);
n -= i;
@@ -159,10 +159,10 @@ void COLUMN::Prints(PGLOBAL, char *ps, uint z)
char buf[80];
if (Name)
sprintf(buf, "COLUMN: %s.%s table=%p col=%p",
snprintf(buf, sizeof(buf), "COLUMN: %s.%s table=%p col=%p",
((!Qualifier) ? (PSZ)"?" : Qualifier), Name, To_Table, To_Col);
else // LNA
sprintf(buf, "C%d", (!Qualifier) ? 0 : *(int *)Qualifier);
snprintf(buf, sizeof(buf), "C%d", (!Qualifier) ? 0 : *(int *)Qualifier);
strncpy(ps, buf, z);
ps[z - 1] = '\0';

View File

@@ -2694,7 +2694,7 @@ void DOSCOL::WriteColumn(PGLOBAL g)
for (; i < Dcm; i++)
safe_strcat(fmt, sizeof(fmt), "0");
len = sprintf(Buf, fmt, field - i, Value->GetShortValue());
len = snprintf(Buf, field + 1, fmt, field - i, Value->GetShortValue());
break;
case TYPE_INT:
safe_strcpy(fmt, sizeof(fmt), (Ldz) ? "%0*d" : "%*.d");
@@ -2704,7 +2704,7 @@ void DOSCOL::WriteColumn(PGLOBAL g)
for (; i < Dcm; i++)
safe_strcat(fmt,sizeof(fmt), "0");
len = sprintf(Buf, fmt, field - i, Value->GetIntValue());
len = snprintf(Buf, field + 1, fmt, field - i, Value->GetIntValue());
break;
case TYPE_TINY:
safe_strcpy(fmt, sizeof(fmt), (Ldz) ? "%0*d" : "%*.d");
@@ -2714,7 +2714,7 @@ void DOSCOL::WriteColumn(PGLOBAL g)
for (; i < Dcm; i++)
safe_strcat(fmt, sizeof(fmt), "0");
len = sprintf(Buf, fmt, field - i, Value->GetTinyValue());
len = snprintf(Buf, field + 1, fmt, field - i, Value->GetTinyValue());
break;
case TYPE_DOUBLE:
case TYPE_DECIM:

View File

@@ -355,22 +355,22 @@ bool TDBEXT::MakeSrcdef(PGLOBAL g)
if (!stricmp(ph, "W") && n_placeholders <= 1) {
Query = new(g)STRING(g, strlen(Srcdef) + strlen(fil1));
Query->SetLength(sprintf(Query->GetStr(), Srcdef, fil1));
Query->SetLength(snprintf(Query->GetStr(), Query->GetSize(), Srcdef, fil1));
}
else if (!stricmp(ph, "WH") && n_placeholders <= 2)
{
Query = new(g)STRING(g, strlen(Srcdef) + strlen(fil1) + strlen(fil2));
Query->SetLength(sprintf(Query->GetStr(), Srcdef, fil1, fil2));
Query->SetLength(snprintf(Query->GetStr(), Query->GetSize(), Srcdef, fil1, fil2));
}
else if (!stricmp(ph, "H") && n_placeholders <= 1)
{
Query = new(g)STRING(g, strlen(Srcdef) + strlen(fil2));
Query->SetLength(sprintf(Query->GetStr(), Srcdef, fil2));
Query->SetLength(snprintf(Query->GetStr(), Query->GetSize(), Srcdef, fil2));
}
else if (!stricmp(ph, "HW") && n_placeholders <= 2)
{
Query = new(g)STRING(g, strlen(Srcdef) + strlen(fil1) + strlen(fil2));
Query->SetLength(sprintf(Query->GetStr(), Srcdef, fil2, fil1));
Query->SetLength(snprintf(Query->GetStr(), Query->GetSize(), Srcdef, fil2, fil1));
} else {
safe_strcpy(g->Message, sizeof(g->Message), "MakeSQL: Wrong place holders specification");
return true;

View File

@@ -416,7 +416,7 @@ PQRYRES CSVColumns(PGLOBAL g, PCSZ dp, PTOS topt, bool info)
/*********************************************************************/
for (i = 0; i < imax; i++) {
if (i >= hmax) {
sprintf(buf, "COL%.3d", i+1);
snprintf(buf, sizeof(buf), "COL%.3d", i+1);
p = buf;
} else
p = colname[i];

View File

@@ -177,7 +177,7 @@ int JDBCDEF::ParseURL(PGLOBAL g, char *url, bool b)
if (server->port) {
char buf[16];
sprintf(buf, "%ld", server->port);
snprintf(buf, sizeof(buf), "%ld", server->port);
strcat(strcat(Url, ":"), buf);
} // endif port

View File

@@ -488,7 +488,7 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j)
n = sizeof(fmt) - (strlen(fmt) + 1);
if (!tdp->Xcol || stricmp(tdp->Xcol, key)) {
sprintf(buf, "%d", k);
snprintf(buf, sizeof(buf), "%d", k);
if (tdp->Uri) {
strncat(strncat(fmt, sep, n), buf, n - strlen(sep));

View File

@@ -321,9 +321,9 @@ void TDB::Printf(PGLOBAL g, FILE *f, uint n)
} // end of Printf
void TDB::Prints(PGLOBAL, char *ps, uint)
void TDB::Prints(PGLOBAL, char *ps, uint z)
{
sprintf(ps, "R%d.%s", Tdb_No, Name);
snprintf(ps, z, "R%d.%s", Tdb_No, Name);
} // end of Prints
/* -------------------------- class TDBASE --------------------------- */

View File

@@ -386,7 +386,7 @@ void MACCOL::ReadColumn(PGLOBAL g)
if (i)
strcat(p++, "-");
p += sprintf(p, "%.2X", adp->Address[i]);
p += snprintf(p, sizeof(buf) - (p - buf), "%.2X", adp->Address[i]);
} // endfor i
p = buf;
@@ -401,7 +401,7 @@ void MACCOL::ReadColumn(PGLOBAL g)
case IF_LOOPBACK_ADAPTERTYPE: p = "Loop Back Adapter"; break;
// case IF_SLIP_ADAPTERTYPE: p = "Generic Slip Adapter"; break;
default:
sprintf(buf, "Other Adapter, type=%d", adp->Type);
snprintf(buf, sizeof(buf), "Other Adapter, type=%d", adp->Type);
p = buf;
} // endswitch Type
#endif // 0
@@ -443,7 +443,7 @@ void MACCOL::ReadColumn(PGLOBAL g)
break;
default:
if (Buf_Type == TYPE_STRING) {
sprintf(buf, "Invalid flag value %d", Flag);
snprintf(buf, sizeof(buf), "Invalid flag value %d", Flag);
p = buf;
} else
n = 0;

View File

@@ -957,7 +957,7 @@ void DIRCOL::SetTimeValue(PGLOBAL g, FILETIME& ftime)
SYSTEMTIME stp;
if (FileTimeToSystemTime(&ftime, &stp)) {
sprintf(tsp, "%04d-%02d-%02d %02d:%02d:%02d",
snprintf(tsp, sizeof(tsp), "%04d-%02d-%02d %02d:%02d:%02d",
stp.wYear, stp.wMonth, stp.wDay, stp.wHour, stp.wMinute, stp.wSecond);
if (Value->GetType() != TYPE_STRING) {

View File

@@ -286,7 +286,7 @@ void TDBODBC::SetFile(PGLOBAL g, PCSZ fn)
} // endif n
// Make the complete connect string
sprintf(Connect, MulConn, fn);
snprintf(Connect, BufSize, MulConn, fn);
} // endif MultConn
DBQ = PlugDup(g, fn);

View File

@@ -243,8 +243,9 @@ PQRYRES PIVAID::MakePivotColumns(PGLOBAL g)
// if (Myc.ExecSQL(g, "SET character_set_results=NULL", &w) == RC_FX)
// goto err;
size_t query_size = strlen(Picol) + strlen(Tabname) + 30;
query = (char*)PlugSubAlloc(g, NULL, 0);
sprintf(query, "SELECT DISTINCT `%s` FROM `%s`", Picol, Tabname);
snprintf(query, query_size, "SELECT DISTINCT `%s` FROM `%s`", Picol, Tabname);
PlugSubAlloc(g, NULL, strlen(query) + 1);
Myc.FreeResult();

View File

@@ -73,7 +73,7 @@ int Xcurl(PGLOBAL g, PCSZ Http, PCSZ Uri, PCSZ filename)
STARTUPINFO si;
PROCESS_INFORMATION pi;
sprintf(cmd, "curl \"%s\" -o \"%s\"", buf, filename);
snprintf(cmd, sizeof(cmd), "curl \"%s\" -o \"%s\"", buf, filename);
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
@@ -118,7 +118,7 @@ int Xcurl(PGLOBAL g, PCSZ Http, PCSZ Uri, PCSZ filename)
#else
pID = fork();
#endif
sprintf(fn, "-o%s", filename);
snprintf(fn, sizeof(fn), "-o%s", filename);
if (pID == 0) {
// Code executed by child process

View File

@@ -86,8 +86,8 @@ TABLE_SHARE *GetTableShare(PGLOBAL g, THD *thd, const char *db,
uint k;
TABLE_SHARE *s;
k = sprintf(key, "%s", db) + 1;
k += sprintf(key + k, "%s", name);
k = snprintf(key, sizeof(key), "%s", db) + 1;
k += snprintf(key + k, sizeof(key) - k, "%s", name);
key[++k] = 0;
if (!(s = alloc_table_share(db, name, key, ++k))) {

View File

@@ -143,7 +143,7 @@ bool VCTDEF::Erase(char *filename)
MakeFnPattern(fpat);
for (i = 1, cdp = To_Cols; cdp; i++, cdp = cdp->GetNext()) {
sprintf(filename, fpat, i);
snprintf(filename, _MAX_PATH, fpat, i);
//#if defined(_WIN32)
// rc |= !DeleteFile(filename);
//#else // UNIX
@@ -189,7 +189,7 @@ int VCTDEF::MakeFnPattern(char *fpat)
for (n = 1, m = ncol; m /= 10; n++) ;
sprintf(pat, "%%0%dd", n);
snprintf(pat, sizeof(pat), "%%0%dd", n);
_splitpath(Fn, drive, direc, fname, ftype);
strcat(fname, pat);
_makepath(fpat, drive, direc, fname, ftype);

View File

@@ -268,14 +268,14 @@ bool TYPBLK<TYPE>::Init(PGLOBAL g, bool check)
template <class TYPE>
char *TYPBLK<TYPE>::GetCharString(char *p, int n)
{
sprintf(p, Fmt, UnalignedRead(n));
snprintf(p, 32, Fmt, UnalignedRead(n));
return p;
} // end of GetCharString
template <>
char *TYPBLK<double>::GetCharString(char *p, int n)
{
sprintf(p, Fmt, Prec, UnalignedRead(n));
snprintf(p, 32, Fmt, Prec, UnalignedRead(n));
return p;
} // end of GetCharString

View File

@@ -900,7 +900,7 @@ int TYPVAL<double>::ShowValue(char *buf, int len)
template <class TYPE>
char *TYPVAL<TYPE>::GetCharString(char *p)
{
sprintf(p, Fmt, Tval);
snprintf(p, 32, Fmt, Tval);
return p;
} // end of GetCharString
@@ -919,7 +919,7 @@ char *TYPVAL<double>::GetCharString(char *p)
template <class TYPE>
char *TYPVAL<TYPE>::GetShortString(char *p, int n)
{
sprintf(p, "%*hd", n, (short)Tval);
snprintf(p, 32, "%*hd", n, (short)Tval);
return p;
} // end of GetShortString
@@ -929,7 +929,7 @@ char *TYPVAL<TYPE>::GetShortString(char *p, int n)
template <class TYPE>
char *TYPVAL<TYPE>::GetIntString(char *p, int n)
{
sprintf(p, "%*d", n, (int)Tval);
snprintf(p, 32, "%*d", n, (int)Tval);
return p;
} // end of GetIntString
@@ -939,7 +939,7 @@ char *TYPVAL<TYPE>::GetIntString(char *p, int n)
template <class TYPE>
char *TYPVAL<TYPE>::GetBigintString(char *p, int n)
{
sprintf(p, "%*lld", n, (longlong)Tval);
snprintf(p, 32, "%*lld", n, (longlong)Tval);
return p;
} // end of GetBigintString
@@ -949,7 +949,7 @@ char *TYPVAL<TYPE>::GetBigintString(char *p, int n)
template <class TYPE>
char *TYPVAL<TYPE>::GetFloatString(char *p, int n, int prec)
{
sprintf(p, "%*.*lf", n, (prec < 0) ? 2 : prec, (double)Tval);
snprintf(p, 32, "%*.*lf", n, (prec < 0) ? 2 : prec, (double)Tval);
return p;
} // end of GetFloatString
@@ -959,7 +959,7 @@ char *TYPVAL<TYPE>::GetFloatString(char *p, int n, int prec)
template <class TYPE>
char *TYPVAL<TYPE>::GetTinyString(char *p, int n)
{
sprintf(p, "%*d", n, (int)(char)Tval);
snprintf(p, 32, "%*d", n, (int)(char)Tval);
return p;
} // end of GetIntString
#endif // 0
@@ -1208,7 +1208,7 @@ bool TYPVAL<TYPE>::FormatValue(PVAL vp, PCSZ fmt)
// This function is wrong and should never be called
assert(false);
char *buf = (char*)vp->GetTo_Val(); // Not big enough
int n = sprintf(buf, fmt, Tval);
int n = snprintf(buf, vp->GetValLen() + 1, fmt, Tval);
return (n > vp->GetValLen());
} // end of FormatValue
@@ -1222,7 +1222,7 @@ bool TYPVAL<TYPE>::SetConstFormat(PGLOBAL g, FORMAT& fmt)
char c[32];
fmt.Type[0] = *GetFormatType(Type);
fmt.Length = sprintf(c, Fmt, Tval);
fmt.Length = snprintf(c, sizeof(c), Fmt, Tval);
fmt.Prec = Prec;
return false;
} // end of SetConstFormat
@@ -1432,7 +1432,7 @@ void TYPVAL<PSZ>::SetValue(int n)
{
char buf[16];
PGLOBAL& g = Global;
int k = sprintf(buf, "%d", n);
int k = snprintf(buf, sizeof(buf), "%d", n);
if (k > Len) {
snprintf(g->Message, sizeof(g->Message), MSG(VALSTR_TOO_LONG), buf, Len);
@@ -1450,7 +1450,7 @@ void TYPVAL<PSZ>::SetValue(uint n)
{
char buf[16];
PGLOBAL& g = Global;
int k = sprintf(buf, "%u", n);
int k = snprintf(buf, sizeof(buf), "%u", n);
if (k > Len) {
snprintf(g->Message, sizeof(g->Message), MSG(VALSTR_TOO_LONG), buf, Len);
@@ -1486,7 +1486,7 @@ void TYPVAL<PSZ>::SetValue(longlong n)
{
char buf[24];
PGLOBAL& g = Global;
int k = sprintf(buf, "%lld", n);
int k = snprintf(buf, sizeof(buf), "%lld", n);
if (k > Len) {
snprintf(g->Message, sizeof(g->Message), MSG(VALSTR_TOO_LONG), buf, Len);
@@ -1504,7 +1504,7 @@ void TYPVAL<PSZ>::SetValue(ulonglong n)
{
char buf[24];
PGLOBAL& g = Global;
int k = sprintf(buf, "%llu", n);
int k = snprintf(buf, sizeof(buf), "%llu", n);
if (k > Len) {
snprintf(g->Message, sizeof(g->Message), MSG(VALSTR_TOO_LONG), buf, Len);
@@ -1522,7 +1522,7 @@ void TYPVAL<PSZ>::SetValue(double f)
{
char *p, buf[64];
PGLOBAL& g = Global;
int k = sprintf(buf, "%lf", f);
int k = snprintf(buf, sizeof(buf), "%lf", f);
for (p = buf + k - 1; p >= buf; p--)
if (*p == '0') {
@@ -1717,7 +1717,7 @@ bool TYPVAL<PSZ>::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op)
bool TYPVAL<PSZ>::FormatValue(PVAL vp, PCSZ fmt)
{
char *buf = (char*)vp->GetTo_Val(); // Should be big enough
int n = sprintf(buf, fmt, Strp);
int n = snprintf(buf, vp->GetValLen() + 1, fmt, Strp);
return (n > vp->GetValLen());
} // end of FormatValue
@@ -2295,7 +2295,7 @@ char *BINVAL::GetCharString(char *)
if (!Chrp)
Chrp = (char*)PlugSubAlloc(Global, NULL, Clen * 2 + 1);
sprintf(Chrp, GetXfmt(), Len, Binp);
snprintf(Chrp, Clen * 2 + 1, GetXfmt(), Len, Binp);
return Chrp;
} // end of GetCharString
@@ -2331,7 +2331,7 @@ bool BINVAL::IsEqual(PVAL vp, bool chktype)
bool BINVAL::FormatValue(PVAL vp, PCSZ fmt)
{
char *buf = (char*)vp->GetTo_Val(); // Should be big enough
int n = sprintf(buf, fmt, Len, Binp);
int n = snprintf(buf, vp->GetValLen() + 1, fmt, Len, Binp);
return (n > vp->GetValLen());
} // end of FormatValue
@@ -2774,7 +2774,7 @@ char *DTVAL::GetCharString(char *p)
return Sdate;
} else
sprintf(p, "%d", Tval);
snprintf(p, 32, "%d", Tval);
//Null = false; ??????????????
return p;

View File

@@ -434,7 +434,7 @@ bool XINDEX::Make(PGLOBAL g, PIXDEF sxp)
/* Get the starting information for progress. */
/*********************************************************************/
dup->Step = (char*)PlugSubAlloc(g, NULL, 128);
sprintf((char*)dup->Step, MSG(BUILD_INDEX), Xdp->GetName(), Tdbp->Name);
snprintf((char*)dup->Step, 128, MSG(BUILD_INDEX), Xdp->GetName(), Tdbp->Name);
dup->ProgMax = Tdbp->GetProgMax(g);
dup->ProgCur = 0;
#endif // 0

View File

@@ -141,25 +141,27 @@ bool CONSTANT::Compare(PXOB xp)
/***********************************************************************/
bool CONSTANT::Rephrase(PGLOBAL g, PSZ work)
{
size_t cur_len = strlen(work);
switch (Value->GetType()) {
case TYPE_STRING:
sprintf(work + strlen(work), "'%s'", Value->GetCharValue());
snprintf(work + cur_len, MAX_STR - cur_len, "'%s'", Value->GetCharValue());
break;
case TYPE_SHORT:
sprintf(work + strlen(work), "%hd", Value->GetShortValue());
snprintf(work + cur_len, MAX_STR - cur_len, "%hd", Value->GetShortValue());
break;
case TYPE_INT:
case TYPE_DATE:
sprintf(work + strlen(work), "%d", Value->GetIntValue());
snprintf(work + cur_len, MAX_STR - cur_len, "%d", Value->GetIntValue());
break;
case TYPE_DOUBLE:
sprintf(work + strlen(work), "%lf", Value->GetFloatValue());
snprintf(work + cur_len, MAX_STR - cur_len, "%lf", Value->GetFloatValue());
break;
case TYPE_BIGINT:
sprintf(work + strlen(work), "%lld", Value->GetBigintValue());
snprintf(work + cur_len, MAX_STR - cur_len, "%lld", Value->GetBigintValue());
break;
case TYPE_TINY:
sprintf(work + strlen(work), "%d", Value->GetTinyValue());
snprintf(work + cur_len, MAX_STR - cur_len, "%d", Value->GetTinyValue());
break;
default:
snprintf(g->Message, sizeof(g->Message), MSG(BAD_CONST_TYPE), Value->GetType());

View File

@@ -2447,8 +2447,8 @@ int ha_federated::index_read_idx_with_result_set(uchar *buf, uint index,
if (real_query(sql_query.ptr(), sql_query.length()))
{
sprintf(error_buffer, "error: %d '%s'",
mysql_errno(mysql), mysql_error(mysql));
snprintf(error_buffer, sizeof(error_buffer), "error: %d '%s'",
mysql_errno(mysql), mysql_error(mysql));
retval= ER_QUERY_ON_FOREIGN_DATA_SOURCE;
goto error;
}

View File

@@ -74,7 +74,7 @@ int main(int argc, char **argv)
for (i=49 ; i>=1 ; i-=2 )
{
j=i%25 +1;
sprintf((char*) key,"%6d",j);
snprintf((char*) key, sizeof(key), "%6d",j);
bmove(record+1,key,6);
error=heap_write(file,record);
if (heap_check_heap(file,0))
@@ -96,7 +96,7 @@ int main(int argc, char **argv)
for (i=1 ; i<=10 ; i++)
{
if (i == remove_ant) { (void) heap_close(file); return (0) ; }
sprintf((char*) key,"%6d",(j=(int) ((rand() & 32767)/32767.*25)));
snprintf((char*) key, sizeof(key), "%6d",(j=(int) ((rand() & 32767)/32767.*25)));
if ((error = heap_rkey(file,record,0,key,6,HA_READ_KEY_EXACT)))
{
if (verbose || (flags[j] == 1 ||
@@ -120,7 +120,7 @@ int main(int argc, char **argv)
printf("- Reading records with key\n");
for (i=1 ; i<=25 ; i++)
{
sprintf((char*) key,"%6d",i);
snprintf((char*) key, sizeof(key), "%6d",i);
bmove(record+1,key,6);
my_errno=0;
error=heap_rkey(file,record,0,key,6,HA_READ_KEY_EXACT);

View File

@@ -174,7 +174,7 @@ int main(int argc, char *argv[])
for (j=rnd(1000)+1 ; j>0 && key1[j] == 0 ; j--) ;
if (j != 0)
{
sprintf((char*) key,"%6d",j);
snprintf((char*) key, sizeof(key), "%6d",j);
if (heap_rkey(file,record,0,key,6, HA_READ_KEY_EXACT))
{
printf("can't find key1: \"%s\"\n",(char*) key);
@@ -229,7 +229,7 @@ int main(int argc, char *argv[])
for (j=rnd(1000)+1 ; j>0 && key1[j] == 0 ; j--) ;
if (!key1[j])
continue;
sprintf((char*) key,"%6d",j);
snprintf((char*) key, sizeof(key), "%6d",j);
if (heap_rkey(file,record,0,key,6, HA_READ_KEY_EXACT))
{
printf("can't find key1: \"%s\"\n",(char*) key);
@@ -272,7 +272,7 @@ int main(int argc, char *argv[])
for (i=999, dupp_keys=found_key=0 ; i>0 ; i--)
{
if (key1[i] > dupp_keys) { dupp_keys=key1[i]; found_key=i; }
sprintf((char*) key,"%6d",found_key);
snprintf((char*) key, sizeof(key), "%6d",found_key);
}
if (dupp_keys > 3)
@@ -461,7 +461,7 @@ int main(int argc, char *argv[])
for (i=999, dupp_keys=found_key=0 ; i>0 ; i--)
{
if (key1[i] > dupp_keys) { dupp_keys=key1[i]; found_key=i; }
sprintf((char*) key,"%6d",found_key);
snprintf((char*) key, sizeof(key), "%6d",found_key);
}
printf("- Read through all keys with first-next-last-prev\n");
ant=0;
@@ -636,8 +636,8 @@ static void make_record(uchar *record, uint n1, uint n2, uint n3,
const char *mark, uint count)
{
bfill(record,reclength,' ');
sprintf((char*) record,"%6d:%4d:%8d:%3.3s: %4d",
n1,n2,n3,mark,count);
snprintf((char*) record, reclength, "%6d:%4d:%8d:%3.3s: %4d",
n1,n2,n3,mark,count);
record[37]='A'; /* Store A in null key */
record[38]=1; /* set as null */
}

View File

@@ -404,7 +404,7 @@ done:
/* success */
ut_sprintf_timestamp(now);
ut_sprintf_timestamp(now, sizeof(now));
buf_dump_status(STATUS_INFO,
"Buffer pool(s) dump completed at %s", now);
@@ -487,7 +487,7 @@ buf_load()
dump_n * sizeof(*dump)));
} else {
fclose(f);
ut_sprintf_timestamp(now);
ut_sprintf_timestamp(now, sizeof(now));
buf_load_status(STATUS_INFO,
"Buffer pool(s) load completed at %s"
" (%s was empty)", now, full_filename);
@@ -553,7 +553,7 @@ buf_load()
if (dump_n == 0) {
ut_free(dump);
ut_sprintf_timestamp(now);
ut_sprintf_timestamp(now, sizeof(now));
buf_load_status(STATUS_INFO,
"Buffer pool(s) load completed at %s"
" (%s was empty or had errors)", now, full_filename);
@@ -668,7 +668,7 @@ buf_load()
os_aio_wait_until_no_pending_reads(true);
ut_sprintf_timestamp(now);
ut_sprintf_timestamp(now, sizeof(now));
if (i == dump_n) {
buf_load_status(STATUS_INFO,

View File

@@ -1734,13 +1734,15 @@ dict_table_rename_in_cache(
char table_name[MAX_TABLE_NAME_LEN + 1];
uint errors = 0;
size_t id_alloc_len=
strlen(table->name.m_name)
+ strlen(old_id) + 1;
if (strlen(table->name.m_name)
> strlen(old_name)) {
foreign->id = static_cast<char*>(
mem_heap_alloc(
foreign->heap,
strlen(table->name.m_name)
+ strlen(old_id) + 1));
id_alloc_len));
}
/* Convert the table name to UTF-8 */
@@ -1769,10 +1771,15 @@ dict_table_rename_in_cache(
strcat(foreign->id,
old_id + strlen(old_name));
} else {
sprintf(strchr(foreign->id, '/') + 1,
"%s%s",
strchr(table_name, '/') +1,
strstr(old_id, "_ibfk_") );
char *slash= strchr(foreign->id, '/');
size_t remaining=
id_alloc_len
- (size_t) (slash + 1
- foreign->id);
snprintf(slash + 1, remaining,
"%s%s",
strchr(table_name, '/') + 1,
strstr(old_id, "_ibfk_"));
}
} else {

View File

@@ -144,7 +144,8 @@ fts_config_create_index_param_name(
::strcpy(name, param);
name[len] = '_';
fts_write_object_id(index->id, name + len + 1);
fts_write_object_id(index->id, name + len + 1,
FTS_AUX_MIN_TABLE_ID_LENGTH + 1);
return(name);
}

Some files were not shown because too many files have changed in this diff Show More