diff options
author | Sergei Golubchik <sergii@pisem.net> | 2013-04-17 19:42:34 +0200 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2013-04-17 19:42:34 +0200 |
commit | 07315d36030bd1cbe6acfeb3e8f60c49ba876a10 (patch) | |
tree | 9c74de4bb97507ece945576df7073a7a28f07674 | |
parent | 4656060f118caba30912cca2557d72fcea307283 (diff) | |
download | mariadb-git-07315d36030bd1cbe6acfeb3e8f60c49ba876a10.tar.gz |
strmake_buf(X,Y) helper, equivalent to strmake(X,Y,sizeof(X)-1)
with a bit of lame protection against abuse.
-rw-r--r-- | client/mysql.cc | 22 | ||||
-rw-r--r-- | client/mysqltest.cc | 3 | ||||
-rw-r--r-- | include/m_string.h | 9 | ||||
-rw-r--r-- | libmysqld/lib_sql.cc | 13 | ||||
-rw-r--r-- | mysys/mf_format.c | 2 | ||||
-rw-r--r-- | mysys/my_thr_init.c | 2 | ||||
-rw-r--r-- | sql-common/client.c | 4 | ||||
-rw-r--r-- | sql/handler.cc | 2 | ||||
-rw-r--r-- | sql/item.cc | 2 | ||||
-rw-r--r-- | sql/log.cc | 27 | ||||
-rw-r--r-- | sql/mysql_install_db.cc | 2 | ||||
-rw-r--r-- | sql/mysqld.cc | 18 | ||||
-rw-r--r-- | sql/rpl_rli.cc | 18 | ||||
-rw-r--r-- | sql/slave.cc | 16 | ||||
-rw-r--r-- | sql/sql_acl.cc | 17 | ||||
-rw-r--r-- | sql/sql_base.cc | 4 | ||||
-rw-r--r-- | sql/sql_class.cc | 2 | ||||
-rw-r--r-- | sql/sql_connect.cc | 2 | ||||
-rw-r--r-- | sql/sql_error.cc | 4 | ||||
-rw-r--r-- | sql/sql_insert.cc | 3 | ||||
-rw-r--r-- | sql/sql_plugin_compat.h | 4 | ||||
-rw-r--r-- | sql/sql_repl.cc | 35 | ||||
-rw-r--r-- | sql/tztime.cc | 4 | ||||
-rw-r--r-- | storage/federated/ha_federated.cc | 2 | ||||
-rw-r--r-- | storage/federatedx/ha_federatedx.cc | 2 | ||||
-rw-r--r-- | storage/maria/ma_recovery.c | 2 | ||||
-rw-r--r-- | storage/myisammrg/ha_myisammrg.cc | 2 |
27 files changed, 102 insertions, 121 deletions
diff --git a/client/mysql.cc b/client/mysql.cc index ad792abc23f..3cd078ac1ce 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -1635,7 +1635,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), { switch(optid) { case OPT_CHARSETS_DIR: - strmake(mysql_charsets_dir, argument, sizeof(mysql_charsets_dir) - 1); + strmake_buf(mysql_charsets_dir, argument); charsets_dir = mysql_charsets_dir; break; case OPT_DELIMITER: @@ -1648,7 +1648,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), /* Check that delimiter does not contain a backslash */ if (!strstr(argument, "\\")) { - strmake(delimiter, argument, sizeof(delimiter) - 1); + strmake_buf(delimiter, argument); } else { @@ -1680,7 +1680,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), if (argument && strlen(argument)) { default_pager_set= 1; - strmake(pager, argument, sizeof(pager) - 1); + strmake_buf(pager, argument); strmov(default_pager, pager); } else if (default_pager_set) @@ -2961,7 +2961,7 @@ com_charset(String *buffer __attribute__((unused)), char *line) { char buff[256], *param; CHARSET_INFO * new_cs; - strmake(buff, line, sizeof(buff) - 1); + strmake_buf(buff, line); param= get_arg(buff, 0); if (!param || !*param) { @@ -3198,7 +3198,7 @@ static void init_tee(const char *file_name) return; } OUTFILE = new_outfile; - strmake(outfile, file_name, FN_REFLEN-1); + strmake_buf(outfile, file_name); tee_fprintf(stdout, "Logging to file '%s'\n", file_name); opt_outfile= 1; return; @@ -3827,7 +3827,7 @@ com_tee(String *buffer __attribute__((unused)), /* eliminate the spaces before the parameters */ while (my_isspace(charset_info,*param)) param++; - end= strmake(file_name, param, sizeof(file_name) - 1); + end= strmake_buf(file_name, param); /* remove end space from command line */ while (end > file_name && (my_isspace(charset_info,end[-1]) || my_iscntrl(charset_info,end[-1]))) @@ -3888,7 +3888,7 @@ com_pager(String *buffer __attribute__((unused)), } else { - end= strmake(pager_name, param, sizeof(pager_name)-1); + end= strmake_buf(pager_name, param); while (end > pager_name && (my_isspace(charset_info,end[-1]) || my_iscntrl(charset_info,end[-1]))) end--; @@ -4101,7 +4101,7 @@ static int com_source(String *buffer __attribute__((unused)), INFO_ERROR, 0); while (my_isspace(charset_info,*param)) param++; - end=strmake(source_name,param,sizeof(source_name)-1); + end=strmake_buf(source_name, param); while (end > source_name && (my_isspace(charset_info,end[-1]) || my_iscntrl(charset_info,end[-1]))) end--; @@ -4154,7 +4154,7 @@ com_delimiter(String *buffer __attribute__((unused)), char *line) { char buff[256], *tmp; - strmake(buff, line, sizeof(buff) - 1); + strmake_buf(buff, line); tmp= get_arg(buff, 0); if (!tmp || !*tmp) @@ -4171,7 +4171,7 @@ com_delimiter(String *buffer __attribute__((unused)), char *line) return 0; } } - strmake(delimiter, tmp, sizeof(delimiter) - 1); + strmake_buf(delimiter, tmp); delimiter_length= (int)strlen(delimiter); delimiter_str= delimiter; return 0; @@ -4185,7 +4185,7 @@ com_use(String *buffer __attribute__((unused)), char *line) int select_db; bzero(buff, sizeof(buff)); - strmake(buff, line, sizeof(buff) - 1); + strmake_buf(buff, line); tmp= get_arg(buff, 0); if (!tmp || !*tmp) { diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 8c6c1cb3408..2dde607a016 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -6335,8 +6335,7 @@ void do_delimiter(struct st_command* command) if (!(*p)) die("Can't set empty delimiter"); - strmake(delimiter, p, sizeof(delimiter) - 1); - delimiter_length= strlen(delimiter); + delimiter_length= strmake_buf(delimiter, p) - delimiter; DBUG_PRINT("exit", ("delimiter: %s", delimiter)); command->last_argument= p + delimiter_length; diff --git a/include/m_string.h b/include/m_string.h index 9efa0376942..990f78eb555 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -108,6 +108,15 @@ extern char *strcend(const char *, pchar); extern char *strfill(char * s,size_t len,pchar fill); extern char *strmake(char *dst,const char *src,size_t length); +#if !defined(__GNUC__) || (__GNUC__ < 4) +#define strmake_buf(D,S) strmake(D, S, sizeof(D) - 1) +#else +#define strmake_buf(D,S) ({ \ + compile_time_assert(sizeof(D) != sizeof(char*)); \ + strmake(D, S, sizeof(D) - 1); \ + }) +#endif + #ifndef strmov extern char *strmov(char *dst,const char *src); #endif diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index 298907b2644..e73fe4b8b77 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -90,7 +90,7 @@ void embedded_get_error(MYSQL *mysql, MYSQL_DATA *data) NET *net= &mysql->net; struct embedded_query_result *ei= data->embedded_info; net->last_errno= ei->last_errno; - strmake(net->last_error, ei->info, sizeof(net->last_error)-1); + strmake_buf(net->last_error, ei->info); memcpy(net->sqlstate, ei->sqlstate, sizeof(net->sqlstate)); mysql->server_status= ei->server_status; my_free(data); @@ -703,8 +703,8 @@ int check_embedded_connection(MYSQL *mysql, const char *db) thd->update_charset(); Security_context *sctx= thd->security_ctx; sctx->host_or_ip= sctx->host= (char*) my_localhost; - strmake(sctx->priv_host, (char*) my_localhost, MAX_HOSTNAME-1); - strmake(sctx->priv_user, mysql->user, USERNAME_LENGTH-1); + strmake_buf(sctx->priv_host, (char*) my_localhost); + strmake_buf(sctx->priv_user, mysql->user); sctx->user= my_strdup(mysql->user, MYF(0)); sctx->proxy_user[0]= 0; sctx->master_access= GLOBAL_ACLS; // Full rights @@ -772,7 +772,7 @@ int check_embedded_connection(MYSQL *mysql, const char *db) return 0; err: - strmake(net->last_error, thd->main_da.message(), sizeof(net->last_error)-1); + strmake_buf(net->last_error, thd->main_da.message()); memcpy(net->sqlstate, mysql_errno_to_sqlstate(thd->main_da.sql_errno()), sizeof(net->sqlstate)-1); @@ -1119,8 +1119,7 @@ net_send_ok(THD *thd, data->embedded_info->affected_rows= affected_rows; data->embedded_info->insert_id= id; if (message) - strmake(data->embedded_info->info, message, - sizeof(data->embedded_info->info)-1); + strmake_buf(data->embedded_info->info, message); bool error= write_eof_packet(thd, server_status, statement_warn_count); thd->cur_data= 0; @@ -1171,7 +1170,7 @@ bool net_send_error_packet(THD *thd, uint sql_errno, const char *err, err, strlen(err), system_charset_info, &error); /* Converted error message is always null-terminated. */ - strmake(ei->info, converted_err, sizeof(ei->info)-1); + strmake_buf(ei->info, converted_err); strmov(ei->sqlstate, sqlstate); ei->server_status= thd->server_status; thd->cur_data= 0; diff --git a/mysys/mf_format.c b/mysys/mf_format.c index 2b2356c08df..d20ce882459 100644 --- a/mysys/mf_format.c +++ b/mysys/mf_format.c @@ -46,7 +46,7 @@ char * fn_format(char * to, const char *name, const char *dir, else if ((flag & MY_RELATIVE_PATH) && !test_if_hard_path(dev)) { /* Put 'dir' before the given path */ - strmake(buff,dev,sizeof(buff)-1); + strmake_buf(buff, dev); pos=convert_dirname(dev,dir,NullS); strmake(pos,buff,sizeof(buff)-1- (int) (pos-dev)); } diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index ac16189f3a7..b9ad379f4c4 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -446,7 +446,7 @@ const char *my_thread_name(void) { my_thread_id id= my_thread_dbug_id(); sprintf(name_buff,"T@%lu", (ulong) id); - strmake(tmp->name,name_buff,THREAD_NAME_SIZE); + strmake_buf(tmp->name, name_buff); } return tmp->name; } diff --git a/sql-common/client.c b/sql-common/client.c index 976c09d7a70..c81fe6a8a69 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -776,7 +776,7 @@ restart: len-=2; if (protocol_41(mysql) && (char) pos[0] == '#') { - strmake(net->sqlstate, (char*) pos+1, SQLSTATE_LENGTH); + strmake_buf(net->sqlstate, (char*) pos+1); pos+= SQLSTATE_LENGTH+1; } else @@ -3120,7 +3120,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, bzero((char*) &UNIXaddr, sizeof(UNIXaddr)); UNIXaddr.sun_family= AF_UNIX; - strmake(UNIXaddr.sun_path, unix_socket, sizeof(UNIXaddr.sun_path)-1); + strmake_buf(UNIXaddr.sun_path, unix_socket); if (connect_sync_or_async(mysql, net, sock, (struct sockaddr *) &UNIXaddr, sizeof(UNIXaddr))) { diff --git a/sql/handler.cc b/sql/handler.cc index 058e219f76c..a4505b807c2 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -2097,7 +2097,7 @@ handle_condition(THD *, { *cond_hdl= NULL; /* Grab the error message */ - strmake(buff, msg, sizeof(buff)-1); + strmake_buf(buff, msg); return TRUE; } diff --git a/sql/item.cc b/sql/item.cc index 54f66375030..9475979aeef 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -4413,7 +4413,7 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list) if (db_name && lower_case_table_names) { /* Convert database to lower case for comparison */ - strmake(name_buff, db_name, sizeof(name_buff)-1); + strmake_buf(name_buff, db_name); my_casedn_str(files_charset_info, name_buff); db_name= name_buff; } diff --git a/sql/log.cc b/sql/log.cc index 112a02bd29e..a73d9fcd079 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -172,7 +172,7 @@ Silence_log_table_errors::handle_condition(THD *, MYSQL_ERROR ** cond_hdl) { *cond_hdl= NULL; - strmake(m_message, msg, sizeof(m_message)-1); + strmake_buf(m_message, msg); return TRUE; } @@ -3183,8 +3183,7 @@ bool MYSQL_BIN_LOG::open(const char *log_name, mysql_file_sync(log_file.file, MYF(MY_WME|MY_SYNC_FILESIZE))) goto err; mysql_mutex_lock(&LOCK_commit_ordered); - strmake(last_commit_pos_file, log_file_name, - sizeof(last_commit_pos_file)-1); + strmake_buf(last_commit_pos_file, log_file_name); last_commit_pos_offset= my_b_tell(&log_file); mysql_mutex_unlock(&LOCK_commit_ordered); @@ -3253,7 +3252,7 @@ int MYSQL_BIN_LOG::get_current_log(LOG_INFO* linfo) int MYSQL_BIN_LOG::raw_get_current_log(LOG_INFO* linfo) { - strmake(linfo->log_file_name, log_file_name, sizeof(linfo->log_file_name)-1); + strmake_buf(linfo->log_file_name, log_file_name); linfo->pos = my_b_tell(&log_file); return 0; } @@ -3691,8 +3690,7 @@ int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included) Reset rli's coordinates to the current log. */ rli->event_relay_log_pos= BIN_LOG_HEADER_SIZE; - strmake(rli->event_relay_log_name,rli->linfo.log_file_name, - sizeof(rli->event_relay_log_name)-1); + strmake_buf(rli->event_relay_log_name,rli->linfo.log_file_name); /* If we removed the rli->group_relay_log_name file, @@ -3702,8 +3700,7 @@ int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included) if (included) { rli->group_relay_log_pos = BIN_LOG_HEADER_SIZE; - strmake(rli->group_relay_log_name,rli->linfo.log_file_name, - sizeof(rli->group_relay_log_name)-1); + strmake_buf(rli->group_relay_log_name,rli->linfo.log_file_name); rli->notify_group_relay_log_name_update(); } @@ -4213,9 +4210,7 @@ int MYSQL_BIN_LOG::purge_logs_before_date(time_t purge_time) else { if (stat_area.st_mtime < purge_time) - strmake(to_log, - log_info.log_file_name, - sizeof(log_info.log_file_name) - 1); + strmake_buf(to_log, log_info.log_file_name); else break; } @@ -4830,8 +4825,7 @@ binlog_start_consistent_snapshot(handlerton *hton, THD *thd) binlog_cache_mngr *const cache_mngr= thd->binlog_setup_trx_data(); /* Server layer calls us with LOCK_commit_ordered locked, so this is safe. */ - strmake(cache_mngr->last_commit_pos_file, mysql_bin_log.last_commit_pos_file, - sizeof(cache_mngr->last_commit_pos_file)-1); + strmake_buf(cache_mngr->last_commit_pos_file, mysql_bin_log.last_commit_pos_file); cache_mngr->last_commit_pos_offset= mysql_bin_log.last_commit_pos_offset; trans_register_ha(thd, TRUE, hton); @@ -6023,8 +6017,7 @@ MYSQL_BIN_LOG::trx_group_commit_leader(group_commit_entry *leader) current->error= write_transaction_or_stmt(current); - strmake(cache_mngr->last_commit_pos_file, log_file_name, - sizeof(cache_mngr->last_commit_pos_file)-1); + strmake_buf(cache_mngr->last_commit_pos_file, log_file_name); commit_offset= my_b_write_tell(&log_file); cache_mngr->last_commit_pos_offset= commit_offset; if (cache_mngr->using_xa && cache_mngr->xa_xid) @@ -7402,7 +7395,7 @@ int TC_LOG_BINLOG::open(const char *opt_name) do { - strmake(log_name, log_info.log_file_name, sizeof(log_name)-1); + strmake_buf(log_name, log_info.log_file_name); } while (!(error= find_next_log(&log_info, 1))); if (error != LOG_INFO_EOF) @@ -7710,7 +7703,7 @@ static void set_binlog_snapshot_file(const char *src) { int dir_len = dirname_length(src); - strmake(binlog_snapshot_file, src + dir_len, sizeof(binlog_snapshot_file)-1); + strmake_buf(binlog_snapshot_file, src + dir_len); } /* diff --git a/sql/mysql_install_db.cc b/sql/mysql_install_db.cc index 6e2c6ec07f3..5d523abb8ae 100644 --- a/sql/mysql_install_db.cc +++ b/sql/mysql_install_db.cc @@ -377,7 +377,7 @@ static int register_service() static void clean_directory(const char *dir) { char dir2[MAX_PATH+2]; - *(strmake(dir2, dir, MAX_PATH+1)+1)= 0; + *(strmake_buf(dir2, dir)+1)= 0; SHFILEOPSTRUCT fileop; fileop.hwnd= NULL; /* no status display */ diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 5e8492f3490..dfabbcfb82c 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -3468,7 +3468,7 @@ static int init_common_variables() WideCharToMultiByte(CP_UTF8,0, wtz_name, -1, system_time_zone, sizeof(system_time_zone) - 1, NULL, NULL); #else - strmake(system_time_zone, tz_name, sizeof(system_time_zone)-1); + strmake_buf(system_time_zone, tz_name); #endif /* _WIN32 */ #endif /* HAVE_TZNAME */ @@ -7332,8 +7332,8 @@ static int mysql_init_variables(void) /* Set directory paths */ mysql_real_data_home_len= - strmake(mysql_real_data_home, get_relative_path(MYSQL_DATADIR), - sizeof(mysql_real_data_home)-1) - mysql_real_data_home; + strmake_buf(mysql_real_data_home, + get_relative_path(MYSQL_DATADIR)) - mysql_real_data_home; /* Replication parameters */ master_info_file= (char*) "master.info", relay_log_info_file= (char*) "relay-log.info"; @@ -7436,7 +7436,7 @@ static int mysql_init_variables(void) const char *tmpenv; if (!(tmpenv = getenv("MY_BASEDIR_VERSION"))) tmpenv = DEFAULT_MYSQL_HOME; - (void) strmake(mysql_home, tmpenv, sizeof(mysql_home)-1); + strmake_buf(mysql_home, tmpenv); #endif return 0; } @@ -7475,7 +7475,7 @@ mysqld_get_one_option(int optid, global_system_variables.tx_isolation= ISO_SERIALIZABLE; break; case 'b': - strmake(mysql_home,argument,sizeof(mysql_home)-1); + strmake_buf(mysql_home, argument); break; case 'C': if (default_collation_name == compiled_default_collation_name) @@ -7486,7 +7486,7 @@ mysqld_get_one_option(int optid, opt_log=1; break; case 'h': - strmake(mysql_real_data_home,argument, sizeof(mysql_real_data_home)-1); + strmake_buf(mysql_real_data_home, argument); /* Correct pointer set by my_getopt (for embedded library) */ mysql_real_data_home_ptr= mysql_real_data_home; break; @@ -7497,7 +7497,7 @@ mysqld_get_one_option(int optid, sql_print_warning("Ignoring user change to '%s' because the user was set to '%s' earlier on the command line\n", argument, mysqld_user); break; case 'L': - strmake(lc_messages_dir, argument, sizeof(lc_messages_dir)-1); + strmake_buf(lc_messages_dir, argument); break; case OPT_BINLOG_FORMAT: binlog_format_used= true; @@ -8182,7 +8182,7 @@ static int fix_paths(void) char *sharedir=get_relative_path(SHAREDIR); if (test_if_hard_path(sharedir)) - strmake(buff,sharedir,sizeof(buff)-1); /* purecov: tested */ + strmake_buf(buff, sharedir); /* purecov: tested */ else strxnmov(buff,sizeof(buff)-1,mysql_home,sharedir,NullS); convert_dirname(buff,buff,NullS); @@ -8190,7 +8190,7 @@ static int fix_paths(void) /* If --character-sets-dir isn't given, use shared library dir */ if (charsets_dir) - strmake(mysql_charsets_dir, charsets_dir, sizeof(mysql_charsets_dir)-1); + strmake_buf(mysql_charsets_dir, charsets_dir); else strxnmov(mysql_charsets_dir, sizeof(mysql_charsets_dir)-1, buff, CHARSET_DIR, NullS); diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index cbd7ac8f5ef..e03d46606d5 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -309,8 +309,7 @@ Failed to open the existing relay log info file '%s' (errno %d)", msg="Error reading slave log configuration"; goto err; } - strmake(rli->event_relay_log_name,rli->group_relay_log_name, - sizeof(rli->event_relay_log_name)-1); + strmake_buf(rli->event_relay_log_name,rli->group_relay_log_name); rli->group_relay_log_pos= rli->event_relay_log_pos= relay_log_pos; rli->group_master_log_pos= master_log_pos; @@ -528,10 +527,8 @@ int init_relay_log_pos(Relay_log_info* rli,const char* log, *errmsg="Could not find target log during relay log initialization"; goto err; } - strmake(rli->group_relay_log_name,rli->linfo.log_file_name, - sizeof(rli->group_relay_log_name)-1); - strmake(rli->event_relay_log_name,rli->linfo.log_file_name, - sizeof(rli->event_relay_log_name)-1); + strmake_buf(rli->group_relay_log_name,rli->linfo.log_file_name); + strmake_buf(rli->event_relay_log_name,rli->linfo.log_file_name); if (rli->relay_log.is_active(rli->linfo.log_file_name)) { /* @@ -871,8 +868,7 @@ void Relay_log_info::inc_group_relay_log_pos(ulonglong log_pos, mysql_mutex_lock(&data_lock); inc_event_relay_log_pos(); group_relay_log_pos= event_relay_log_pos; - strmake(group_relay_log_name,event_relay_log_name, - sizeof(group_relay_log_name)-1); + strmake_buf(group_relay_log_name,event_relay_log_name); notify_group_relay_log_name_update(); @@ -1005,10 +1001,8 @@ int purge_relay_logs(Relay_log_info* rli, THD *thd, bool just_reset, goto err; } /* Save name of used relay log file */ - strmake(rli->group_relay_log_name, rli->relay_log.get_log_fname(), - sizeof(rli->group_relay_log_name)-1); - strmake(rli->event_relay_log_name, rli->relay_log.get_log_fname(), - sizeof(rli->event_relay_log_name)-1); + strmake_buf(rli->group_relay_log_name, rli->relay_log.get_log_fname()); + strmake_buf(rli->event_relay_log_name, rli->relay_log.get_log_fname()); rli->group_relay_log_pos= rli->event_relay_log_pos= BIN_LOG_HEADER_SIZE; if (count_relay_log_space(rli)) { diff --git a/sql/slave.cc b/sql/slave.cc index 0a162f6fbaa..02ab69af0e8 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -359,16 +359,13 @@ int init_recovery(Master_info* mi, const char** errmsg) { mi->master_log_pos= max(BIN_LOG_HEADER_SIZE, rli->group_master_log_pos); - strmake(mi->master_log_name, rli->group_master_log_name, - sizeof(mi->master_log_name)-1); + strmake_buf(mi->master_log_name, rli->group_master_log_name); sql_print_warning("Recovery from master pos %ld and file %s.", (ulong) mi->master_log_pos, mi->master_log_name); - strmake(rli->group_relay_log_name, rli->relay_log.get_log_fname(), - sizeof(rli->group_relay_log_name)-1); - strmake(rli->event_relay_log_name, rli->relay_log.get_log_fname(), - sizeof(mi->rli.event_relay_log_name)-1); + strmake_buf(rli->group_relay_log_name, rli->relay_log.get_log_fname()); + strmake_buf(rli->event_relay_log_name, rli->relay_log.get_log_fname()); rli->group_relay_log_pos= rli->event_relay_log_pos= BIN_LOG_HEADER_SIZE; } @@ -3588,8 +3585,8 @@ log '%s' at position %s, relay log '%s' position: %s", RPL_LOG_NAME, mysql_mutex_lock(&rli->data_lock); if (rli->slave_skip_counter) { - strmake(saved_log_name, rli->group_relay_log_name, FN_REFLEN - 1); - strmake(saved_master_log_name, rli->group_master_log_name, FN_REFLEN - 1); + strmake_buf(saved_log_name, rli->group_relay_log_name); + strmake_buf(saved_master_log_name, rli->group_master_log_name); saved_log_pos= rli->group_relay_log_pos; saved_master_log_pos= rli->group_master_log_pos; saved_skip= rli->slave_skip_counter; @@ -5223,8 +5220,7 @@ static Log_event* next_event(Relay_log_info* rli) goto err; } rli->event_relay_log_pos = BIN_LOG_HEADER_SIZE; - strmake(rli->event_relay_log_name,rli->linfo.log_file_name, - sizeof(rli->event_relay_log_name)-1); + strmake_buf(rli->event_relay_log_name,rli->linfo.log_file_name); flush_relay_log_info(rli); } diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index d1cdf35bb5a..a5ab5c1a816 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -1435,12 +1435,12 @@ bool acl_getroot(Security_context *sctx, char *user, char *host, sctx->master_access= acl_user->access; if (acl_user->user) - strmake(sctx->priv_user, user, USERNAME_LENGTH); + strmake_buf(sctx->priv_user, user); else *sctx->priv_user= 0; if (acl_user->host.hostname) - strmake(sctx->priv_host, acl_user->host.hostname, MAX_HOSTNAME - 1); + strmake_buf(sctx->priv_host, acl_user->host.hostname); else *sctx->priv_host= 0; } @@ -8325,10 +8325,9 @@ static bool find_mpvio_user(MPVIO_EXT *mpvio) mpvio->auth_info.user_name= sctx->user; mpvio->auth_info.user_name_length= strlen(sctx->user); mpvio->auth_info.auth_string= mpvio->acl_user->auth_string.str; - mpvio->auth_info.auth_string_length= - (unsigned long) mpvio->acl_user->auth_string.length; - strmake(mpvio->auth_info.authenticated_as, mpvio->acl_user->user ? - mpvio->acl_user->user : "", USERNAME_LENGTH); + mpvio->auth_info.auth_string_length= (unsigned long) mpvio->acl_user->auth_string.length; + strmake_buf(mpvio->auth_info.authenticated_as, mpvio->acl_user->user ? + mpvio->acl_user->user : ""); DBUG_PRINT("info", ("exit: user=%s, auth_string=%s, authenticated as=%s" "plugin=%s", @@ -8412,7 +8411,7 @@ static bool parse_com_change_user_packet(MPVIO_EXT *mpvio, uint packet_length) /* Clear variables that are allocated */ thd->user_connect= 0; - strmake(sctx->priv_user, sctx->user, USERNAME_LENGTH); + strmake_buf(sctx->priv_user, sctx->user); if (thd->make_lex_string(&mpvio->db, db_buff, db_len, 0) == 0) DBUG_RETURN(1); /* The error is set by make_lex_string(). */ @@ -9229,12 +9228,12 @@ bool acl_authenticate(THD *thd, uint connect_errors, sctx->master_access= acl_user->access; if (acl_user->user) - strmake(sctx->priv_user, acl_user->user, USERNAME_LENGTH - 1); + strmake_buf(sctx->priv_user, acl_user->user); else *sctx->priv_user= 0; if (acl_user->host.hostname) - strmake(sctx->priv_host, acl_user->host.hostname, MAX_HOSTNAME - 1); + strmake_buf(sctx->priv_host, acl_user->host.hostname); else *sctx->priv_host= 0; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index a02294236f7..56c2a613b1e 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -6914,7 +6914,7 @@ find_field_in_tables(THD *thd, Item_ident *item, We can't do this in Item_field as this would change the 'name' of the item which may be used in the select list */ - strmake(name_buff, db, sizeof(name_buff)-1); + strmake_buf(name_buff, db); my_casedn_str(files_charset_info, name_buff); db= name_buff; } @@ -8487,7 +8487,7 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name, We can't do this in Item_field as this would change the 'name' of the item which may be used in the select list */ - strmake(name_buff, db_name, sizeof(name_buff)-1); + strmake_buf(name_buff, db_name); my_casedn_str(files_charset_info, name_buff); db_name= name_buff; } diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 33dc4218e95..7b3e10c73f1 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -2536,7 +2536,7 @@ select_export::prepare(List<Item> &list, SELECT_LEX_UNIT *u) bool string_results= FALSE, non_string_results= FALSE; unit= u; if ((uint) strlen(exchange->file_name) + NAME_LEN >= FN_REFLEN) - strmake(path,exchange->file_name,FN_REFLEN-1); + strmake_buf(path,exchange->file_name); write_cs= exchange->cs ? exchange->cs : &my_charset_bin; diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 9f6185280cd..7e0b659a3e4 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -435,7 +435,7 @@ void init_user_stats(USER_STATS *user_stats, memcpy(user_stats->user, user, user_length); user_stats->user[user_length]= 0; user_stats->user_name_length= user_length; - strmake(user_stats->priv_user, priv_user, sizeof(user_stats->priv_user)-1); + strmake_buf(user_stats->priv_user, priv_user); user_stats->total_connections= total_connections; user_stats->concurrent_connections= concurrent_connections; diff --git a/sql/sql_error.cc b/sql/sql_error.cc index 06da6250e71..61281af1d0a 100644 --- a/sql/sql_error.cc +++ b/sql/sql_error.cc @@ -367,7 +367,7 @@ Diagnostics_area::set_ok_status(THD *thd, ulonglong affected_rows_arg, m_affected_rows= affected_rows_arg; m_last_insert_id= last_insert_id_arg; if (message_arg) - strmake(m_message, message_arg, sizeof(m_message) - 1); + strmake_buf(m_message, message_arg); else m_message[0]= '\0'; m_status= DA_OK; @@ -435,7 +435,7 @@ Diagnostics_area::set_error_status(THD *thd, uint sql_errno_arg, m_sql_errno= sql_errno_arg; memcpy(m_sqlstate, sqlstate, SQLSTATE_LENGTH); m_sqlstate[SQLSTATE_LENGTH]= '\0'; - strmake(m_message, message_arg, sizeof(m_message)-1); + strmake_buf(m_message, message_arg); m_status= DA_ERROR; DBUG_VOID_RETURN; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index fc6151e44d9..bda443de3c3 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2011,8 +2011,7 @@ public: DBUG_ENTER("Delayed_insert constructor"); thd.security_ctx->user=(char*) delayed_user; thd.security_ctx->host=(char*) my_localhost; - strmake(thd.security_ctx->priv_user, thd.security_ctx->user, - USERNAME_LENGTH); + strmake_buf(thd.security_ctx->priv_user, thd.security_ctx->user); thd.current_tablenr=0; thd.command=COM_DELAYED_INSERT; thd.lex->current_select= 0; // for my_message_sql diff --git a/sql/sql_plugin_compat.h b/sql/sql_plugin_compat.h index 8c6014f8dc6..5c7bb620575 100644 --- a/sql/sql_plugin_compat.h +++ b/sql/sql_plugin_compat.h @@ -16,9 +16,9 @@ /* old plugin api structures, used for backward compatibility */ #define upgrade_var(X) latest->X= X -#define upgrade_str(X) strmake(latest->X, X, sizeof(X)) +#define upgrade_str(X) strmake_buf(latest->X, X) #define downgrade_var(X) X= latest->X -#define downgrade_str(X) strmake(X, latest->X, sizeof(X)-1) +#define downgrade_str(X) strmake_buf(X, latest->X) /**************************************************************/ /* Authentication API, version 0x0100 *************************/ diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 4e5eef14d69..d2f942643a9 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1272,8 +1272,7 @@ int start_slave(THD* thd , Master_info* mi, bool net_report) We don't check thd->lex->mi.log_file_name for NULL here since it is checked in sql_yacc.yy */ - strmake(mi->rli.until_log_name, thd->lex->mi.log_file_name, - sizeof(mi->rli.until_log_name)-1); + strmake_buf(mi->rli.until_log_name, thd->lex->mi.log_file_name); } else if (thd->lex->mi.relay_log_pos) { @@ -1281,8 +1280,7 @@ int start_slave(THD* thd , Master_info* mi, bool net_report) slave_errno=ER_BAD_SLAVE_UNTIL_COND; mi->rli.until_condition= Relay_log_info::UNTIL_RELAY_POS; mi->rli.until_log_pos= thd->lex->mi.relay_log_pos; - strmake(mi->rli.until_log_name, thd->lex->mi.relay_log_name, - sizeof(mi->rli.until_log_name)-1); + strmake_buf(mi->rli.until_log_name, thd->lex->mi.relay_log_name); } else mi->rli.clear_until_condition(); @@ -1639,9 +1637,9 @@ bool change_master(THD* thd, Master_info* mi) /* Before processing the command, save the previous state. */ - strmake(saved_host, mi->host, HOSTNAME_LENGTH); + strmake_buf(saved_host, mi->host); saved_port= mi->port; - strmake(saved_log_name, mi->master_log_name, FN_REFLEN - 1); + strmake_buf(saved_log_name, mi->master_log_name); saved_log_pos= mi->master_log_pos; /* @@ -1656,8 +1654,7 @@ bool change_master(THD* thd, Master_info* mi) } if (lex_mi->log_file_name) - strmake(mi->master_log_name, lex_mi->log_file_name, - sizeof(mi->master_log_name)-1); + strmake_buf(mi->master_log_name, lex_mi->log_file_name); if (lex_mi->pos) { mi->master_log_pos= lex_mi->pos; @@ -1721,15 +1718,15 @@ bool change_master(THD* thd, Master_info* mi) (lex_mi->ssl_verify_server_cert == LEX_MASTER_INFO::LEX_MI_ENABLE); if (lex_mi->ssl_ca) - strmake(mi->ssl_ca, lex_mi->ssl_ca, sizeof(mi->ssl_ca)-1); + strmake_buf(mi->ssl_ca, lex_mi->ssl_ca); if (lex_mi->ssl_capath) - strmake(mi->ssl_capath, lex_mi->ssl_capath, sizeof(mi->ssl_capath)-1); + strmake_buf(mi->ssl_capath, lex_mi->ssl_capath); if (lex_mi->ssl_cert) - strmake(mi->ssl_cert, lex_mi->ssl_cert, sizeof(mi->ssl_cert)-1); + strmake_buf(mi->ssl_cert, lex_mi->ssl_cert); if (lex_mi->ssl_cipher) - strmake(mi->ssl_cipher, lex_mi->ssl_cipher, sizeof(mi->ssl_cipher)-1); + strmake_buf(mi->ssl_cipher, lex_mi->ssl_cipher); if (lex_mi->ssl_key) - strmake(mi->ssl_key, lex_mi->ssl_key, sizeof(mi->ssl_key)-1); + strmake_buf(mi->ssl_key, lex_mi->ssl_key); #ifndef HAVE_OPENSSL if (lex_mi->ssl || lex_mi->ssl_ca || lex_mi->ssl_capath || lex_mi->ssl_cert || lex_mi->ssl_cipher || lex_mi->ssl_key || @@ -1743,10 +1740,8 @@ bool change_master(THD* thd, Master_info* mi) need_relay_log_purge= 0; char relay_log_name[FN_REFLEN]; mi->rli.relay_log.make_log_name(relay_log_name, lex_mi->relay_log_name); - strmake(mi->rli.group_relay_log_name, relay_log_name, - sizeof(mi->rli.group_relay_log_name)-1); - strmake(mi->rli.event_relay_log_name, relay_log_name, - sizeof(mi->rli.event_relay_log_name)-1); + strmake_buf(mi->rli.group_relay_log_name, relay_log_name); + strmake_buf(mi->rli.event_relay_log_name, relay_log_name); } if (lex_mi->relay_log_pos) @@ -1782,8 +1777,7 @@ bool change_master(THD* thd, Master_info* mi) */ mi->master_log_pos = max(BIN_LOG_HEADER_SIZE, mi->rli.group_master_log_pos); - strmake(mi->master_log_name, mi->rli.group_master_log_name, - sizeof(mi->master_log_name)-1); + strmake_buf(mi->master_log_name, mi->rli.group_master_log_name); } /* Relay log's IO_CACHE may not be inited, if rli->inited==0 (server was never @@ -1836,8 +1830,7 @@ bool change_master(THD* thd, Master_info* mi) */ mi->rli.group_master_log_pos= mi->master_log_pos; DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos)); - strmake(mi->rli.group_master_log_name,mi->master_log_name, - sizeof(mi->rli.group_master_log_name)-1); + strmake_buf(mi->rli.group_master_log_name,mi->master_log_name); if (!mi->rli.group_master_log_name[0]) // uninitialized case mi->rli.group_master_log_pos=0; diff --git a/sql/tztime.cc b/sql/tztime.cc index 0e793290bba..95a1001485b 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -2559,7 +2559,7 @@ main(int argc, char **argv) if (argc == 2) { - root_name_end= strmake(fullname, argv[1], FN_REFLEN); + root_name_end= strmake_buf(fullname, argv[1]); printf("TRUNCATE TABLE time_zone;\n"); printf("TRUNCATE TABLE time_zone_name;\n"); @@ -2713,7 +2713,7 @@ main(int argc, char **argv) (int)t, (int)t1); /* Let us load time zone description */ - str_end= strmake(fullname, TZDIR, FN_REFLEN); + str_end= strmake_buf(fullname, TZDIR); strmake(str_end, "/MET", FN_REFLEN - (str_end - fullname)); if (tz_load(fullname, &tz_info, &tz_storage)) diff --git a/storage/federated/ha_federated.cc b/storage/federated/ha_federated.cc index c0bf0acb523..55394e859c5 100644 --- a/storage/federated/ha_federated.cc +++ b/storage/federated/ha_federated.cc @@ -3243,7 +3243,7 @@ int ha_federated::stash_remote_error() if (!mysql) DBUG_RETURN(remote_error_number); remote_error_number= mysql_errno(mysql); - strmake(remote_error_buf, mysql_error(mysql), sizeof(remote_error_buf)-1); + strmake_buf(remote_error_buf, mysql_error(mysql)); if (remote_error_number == ER_DUP_ENTRY || remote_error_number == ER_DUP_KEY) DBUG_RETURN(HA_ERR_FOUND_DUPP_KEY); diff --git a/storage/federatedx/ha_federatedx.cc b/storage/federatedx/ha_federatedx.cc index f6d9b3a4014..eb4d7f11d33 100644 --- a/storage/federatedx/ha_federatedx.cc +++ b/storage/federatedx/ha_federatedx.cc @@ -3439,7 +3439,7 @@ int ha_federatedx::stash_remote_error() if (!io) DBUG_RETURN(remote_error_number); remote_error_number= io->error_code(); - strmake(remote_error_buf, io->error_str(), sizeof(remote_error_buf)-1); + strmake_buf(remote_error_buf, io->error_str()); if (remote_error_number == ER_DUP_ENTRY || remote_error_number == ER_DUP_KEY) DBUG_RETURN(HA_ERR_FOUND_DUPP_KEY); diff --git a/storage/maria/ma_recovery.c b/storage/maria/ma_recovery.c index 9ac42f885b5..0f3fb0f8a1e 100644 --- a/storage/maria/ma_recovery.c +++ b/storage/maria/ma_recovery.c @@ -3304,7 +3304,7 @@ static LSN parse_checkpoint_record(LSN lsn) first_log_write_lsn= lsn_korr(ptr); ptr+= LSN_STORE_SIZE; name_len= strlen((char *)ptr) + 1; - strmake(name, (char *)ptr, sizeof(name)-1); + strmake_buf(name, (char *)ptr); ptr+= name_len; if (new_table(sid, name, first_log_write_lsn)) return LSN_ERROR; diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc index bf27e7c2284..2b571675aef 100644 --- a/storage/myisammrg/ha_myisammrg.cc +++ b/storage/myisammrg/ha_myisammrg.cc @@ -1470,7 +1470,7 @@ static void split_file_name(const char *file_name, char buff[FN_REFLEN]; db->length= 0; - strmake(buff, file_name, sizeof(buff)-1); + strmake_buf(buff, file_name); dir_length= dirname_length(buff); if (dir_length > 1) { |