diff options
Diffstat (limited to 'sql/sql_repl.cc')
-rw-r--r-- | sql/sql_repl.cc | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index db8dc694502..917f4ea1a80 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1641,6 +1641,31 @@ void kill_zombie_dump_threads(uint32 slave_server_id) } } +/** + Get value for a string parameter with error checking + + Note that in case of error the original string should not be updated! + + @ret 0 ok + @ret 1 error +*/ + +static bool get_string_parameter(char *to, const char *from, size_t length, + const char *name) +{ + if (from) // Empty paramaters allowed + { + size_t from_length; + if ((from_length= strlen(from)) > length) + { + my_error(ER_WRONG_STRING_LENGTH, MYF(0), from, name, (int) length); + return 1; + } + memcpy(to, from, from_length+1); + } + return 0; +} + /** Execute a CHANGE MASTER statement. @@ -1651,10 +1676,14 @@ void kill_zombie_dump_threads(uint32 slave_server_id) @param mi Pointer to Master_info object belonging to the slave's IO thread. + @param master_info_added Out parameter saying if the Master_info *mi was + added to the global list of masters. This is useful in error conditions + to know if caller should free Master_info *mi. + @retval FALSE success @retval TRUE error */ -bool change_master(THD* thd, Master_info* mi) +bool change_master(THD* thd, Master_info* mi, bool *master_info_added) { int thread_mask; const char* errmsg= 0; @@ -1669,6 +1698,7 @@ bool change_master(THD* thd, Master_info* mi) LEX_MASTER_INFO* lex_mi= &thd->lex->mi; DBUG_ENTER("change_master"); + *master_info_added= false; /* We need to check if there is an empty master_host. Otherwise change master succeeds, a master.info file is created containing @@ -1717,6 +1747,7 @@ bool change_master(THD* thd, Master_info* mi) ret= TRUE; goto err; } + *master_info_added= true; } if (global_system_variables.log_warnings > 1) sql_print_information("Master: '%.*s' Master_info_file: '%s' " @@ -1769,12 +1800,17 @@ bool change_master(THD* thd, Master_info* mi) } DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos)); - if (lex_mi->host) - strmake(mi->host, lex_mi->host, sizeof(mi->host)-1); - if (lex_mi->user) - strmake(mi->user, lex_mi->user, sizeof(mi->user)-1); - if (lex_mi->password) - strmake(mi->password, lex_mi->password, sizeof(mi->password)-1); + if (get_string_parameter(mi->host, lex_mi->host, sizeof(mi->host)-1, + "MASTER_HOST") || + get_string_parameter(mi->user, lex_mi->user, sizeof(mi->user)-1, + "MASTER_USER") || + get_string_parameter(mi->password, lex_mi->password, + sizeof(mi->password)-1, "MASTER_PASSWORD")) + { + ret= TRUE; + goto err; + } + if (lex_mi->port) mi->port = lex_mi->port; if (lex_mi->connect_retry) |