strmake_buf(X,Y) helper, equivalent to strmake(X,Y,sizeof(X)-1)

with a bit of lame protection against abuse.
This commit is contained in:
Sergei Golubchik 2013-04-17 19:42:34 +02:00
parent 4656060f11
commit 07315d3603
27 changed files with 102 additions and 121 deletions

View file

@ -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)
{

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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)))
{

View file

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

View file

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

View file

@ -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);
}
/*

View file

@ -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 */

View file

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

View file

@ -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))
{

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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 *************************/

View file

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

View file

@ -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))

View file

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

View file

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

View file

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

View file

@ -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)
{