From fecdb6a3848361f17b556bf222723079549b1971 Mon Sep 17 00:00:00 2001 From: Jim Winstead Date: Mon, 21 Sep 2009 15:20:14 -0700 Subject: The mysql command line client ignored the --skip-column-names option when used in conjunction with --vertical. (Bug #47147, patch by Harrison Fisk) --- client/mysql.cc | 3 ++- mysql-test/r/mysql.result | 11 ++++++++--- mysql-test/t/mysql.test | 5 +++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/client/mysql.cc b/client/mysql.cc index bafd173343e..c579d0ccaaa 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -3510,7 +3510,8 @@ print_table_data_vertically(MYSQL_RES *result) for (uint off=0; off < mysql_num_fields(result); off++) { field= mysql_fetch_field(result); - tee_fprintf(PAGER, "%*s: ",(int) max_length,field->name); + if (column_names) + tee_fprintf(PAGER, "%*s: ",(int) max_length,field->name); if (cur[off]) { unsigned int i; diff --git a/mysql-test/r/mysql.result b/mysql-test/r/mysql.result index c02073df677..32917888b81 100644 --- a/mysql-test/r/mysql.result +++ b/mysql-test/r/mysql.result @@ -162,8 +162,8 @@ ERROR 1049 (42000) at line 1: Unknown database 'invalid' ERROR 1049 (42000) at line 1: Unknown database 'invalid' Test connect with dbname + hostname Test connect with dbname + _invalid_ hostname -ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'invalid_hostname' (errno) -ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'invalid_hostname' (errno) +ERROR 2003 (HY000) at line 1: Can't connect to MySQL server on 'invalid_hostname' (errno) +ERROR 2003 (HY000) at line 1: Can't connect to MySQL server on 'invalid_hostname' (errno) The commands reported in the bug report ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyril has found a bug :)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (errno) Too long dbname @@ -198,7 +198,7 @@ COUNT (*) 1 COUNT (*) 1 -ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'invalid_hostname' (errno) +ERROR 2003 (HY000) at line 1: Can't connect to MySQL server on 'invalid_hostname' (errno) End of 5.0 tests WARNING: --server-arg option not supported in this configuration. Warning (Code 1286): Unknown table engine 'nonexistent' @@ -230,4 +230,9 @@ a: b drop table t1; +Bug #47147: mysql client option --skip-column-names does not apply to vertical output + +*************************** 1. row *************************** +1 + End of tests diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test index cffa6392fa3..7b87ae10e59 100644 --- a/mysql-test/t/mysql.test +++ b/mysql-test/t/mysql.test @@ -401,5 +401,10 @@ insert into t1 values ('\0b\0'); --exec $MYSQL --xml test -e "select a from t1" drop table t1; +--echo +--echo Bug #47147: mysql client option --skip-column-names does not apply to vertical output +--echo +--exec $MYSQL --skip-column-names --vertical test -e "select 1 as a" + --echo --echo End of tests -- cgit v1.2.1 From 43e77cd32f77b546264b634c4c4f9b784fa94562 Mon Sep 17 00:00:00 2001 From: Jim Winstead Date: Mon, 23 Nov 2009 13:54:27 -0800 Subject: Fix C99 aliasing violation due to mismatched types that were papered over with a cast. (Bug #48284) --- libmysql/libmysql.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 77ff2a01d7c..98955c8fc89 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -2285,7 +2285,7 @@ mysql_stmt_param_metadata(MYSQL_STMT *stmt) /* Store type of parameter in network buffer. */ -static void store_param_type(char **pos, MYSQL_BIND *param) +static void store_param_type(unsigned char **pos, MYSQL_BIND *param) { uint typecode= param->buffer_type | (param->is_unsigned ? 32768 : 0); int2store(*pos, typecode); @@ -2565,7 +2565,7 @@ int cli_stmt_execute(MYSQL_STMT *stmt) that is sent to the server. */ for (param= stmt->params; param < param_end ; param++) - store_param_type((char**) &net->write_pos, param); + store_param_type(&net->write_pos, param); } for (param= stmt->params; param < param_end; param++) -- cgit v1.2.1 From b9380f0e76b34af223c4ef0b4fe648ddca47a59c Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Thu, 17 Dec 2009 15:58:38 -0200 Subject: Bug#48983: Bad strmake calls (length one too long) The problem is a somewhat common misusage of the strmake function. The strmake(dst, src, len) function writes at most /len/ bytes to the string pointed to by src, not including the trailing null byte. Hence, if /len/ is the exact length of the destination buffer, a one byte buffer overflow can occur if the length of the source string is equal to or greater than /len/. --- client/mysqldump.c | 4 ++-- libmysql/libmysql.c | 7 +++++-- libmysqld/lib_sql.cc | 2 +- mysys/default.c | 2 +- mysys/mf_pack.c | 4 ++-- server-tools/instance-manager/commands.cc | 2 +- server-tools/instance-manager/listener.cc | 2 +- sql/log.cc | 8 ++++---- sql/sp_pcontext.h | 2 +- sql/sql_acl.cc | 4 ++-- sql/sql_parse.cc | 2 +- sql/sql_table.cc | 2 +- 12 files changed, 22 insertions(+), 19 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 1918a657316..9bbf718eebf 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -782,7 +782,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), &err_ptr, &err_len); if (err_len) { - strmake(buff, err_ptr, min(sizeof(buff), err_len)); + strmake(buff, err_ptr, min(sizeof(buff) - 1, err_len)); fprintf(stderr, "Invalid mode to --compatible: %s\n", buff); exit(1); } @@ -3452,7 +3452,7 @@ static ulong find_set(TYPELIB *lib, const char *x, uint length, for (; pos != end && *pos != ','; pos++) ; var_len= (uint) (pos - start); - strmake(buff, start, min(sizeof(buff), var_len)); + strmake(buff, start, min(sizeof(buff) - 1, var_len)); find= find_type(buff, lib, var_len); if (!find) { diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index d287679bebb..62feae1b56e 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -712,7 +712,10 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, if (!passwd) passwd=""; - /* Store user into the buffer */ + /* + Store user into the buffer. + Advance position as strmake returns a pointer to the closing NUL. + */ end= strmake(end, user, USERNAME_LENGTH) + 1; /* write scrambled password according to server capabilities */ @@ -1252,7 +1255,7 @@ mysql_list_fields(MYSQL *mysql, const char *table, const char *wild) { MYSQL_RES *result; MYSQL_FIELD *fields; - char buff[257],*end; + char buff[258],*end; DBUG_ENTER("mysql_list_fields"); DBUG_PRINT("enter",("table: '%s' wild: '%s'",table,wild ? wild : "")); diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index b0a47727c7c..644d4702e55 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -73,7 +73,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)); + strmake(net->last_error, ei->info, sizeof(net->last_error) - 1); memcpy(net->sqlstate, ei->sqlstate, sizeof(net->sqlstate)); mysql->server_status= ei->server_status; my_free((gptr) data, MYF(0)); diff --git a/mysys/default.c b/mysys/default.c index 362aa0d4605..0d162dc13d5 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -605,7 +605,7 @@ static int search_default_file_with_ext(Process_option_func opt_handler, int recursion_level) { char name[FN_REFLEN + 10], buff[4096], curr_gr[4096], *ptr, *end, **tmp_ext; - char *value, option[4096], tmp[FN_REFLEN]; + char *value, option[4096+2], tmp[FN_REFLEN]; static const char includedir_keyword[]= "includedir"; static const char include_keyword[]= "include"; const int max_recursion_level= 10; diff --git a/mysys/mf_pack.c b/mysys/mf_pack.c index d2bac95b391..3053699f457 100644 --- a/mysys/mf_pack.c +++ b/mysys/mf_pack.c @@ -234,7 +234,7 @@ my_bool my_use_symdir=0; /* Set this if you want to use symdirs */ #ifdef USE_SYMDIR void symdirget(char *dir) { - char buff[FN_REFLEN]; + char buff[FN_REFLEN+1]; char *pos=strend(dir); if (dir[0] && pos[-1] != FN_DEVCHAR && my_access(dir, F_OK)) { @@ -246,7 +246,7 @@ void symdirget(char *dir) *pos++=temp; *pos=0; /* Restore old filename */ if (file >= 0) { - if ((length= my_read(file, buff, sizeof(buff), MYF(0))) > 0) + if ((length= my_read(file, buff, sizeof(buff) - 1, MYF(0))) > 0) { for (pos= buff + length ; pos > buff && (iscntrl(pos[-1]) || isspace(pos[-1])) ; diff --git a/server-tools/instance-manager/commands.cc b/server-tools/instance-manager/commands.cc index bb3763ce8c5..5e8ba5087af 100644 --- a/server-tools/instance-manager/commands.cc +++ b/server-tools/instance-manager/commands.cc @@ -651,7 +651,7 @@ Set_option::Set_option(Instance_map *instance_map_arg, instance_name= instance->options.instance_name; /* add prefix for add_option */ - if ((option_len_arg < MAX_OPTION_LEN - 1) || + if ((option_len_arg < MAX_OPTION_LEN - 1) && (option_value_len_arg < MAX_OPTION_LEN - 1)) { strmake(option, option_arg, option_len_arg); diff --git a/server-tools/instance-manager/listener.cc b/server-tools/instance-manager/listener.cc index 36f0cbe85e1..653a807e5fc 100644 --- a/server-tools/instance-manager/listener.cc +++ b/server-tools/instance-manager/listener.cc @@ -331,7 +331,7 @@ create_unix_socket(struct sockaddr_un &unix_socket_address) unix_socket_address.sun_family= AF_UNIX; strmake(unix_socket_address.sun_path, options.socket_file_name, - sizeof(unix_socket_address.sun_path)); + sizeof(unix_socket_address.sun_path) - 1); unlink(unix_socket_address.sun_path); // in case we have stale socket file /* diff --git a/sql/log.cc b/sql/log.cc index c042651216c..4aeab534b23 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -501,7 +501,7 @@ const char *MYSQL_LOG::generate_name(const char *log_name, { char *p = fn_ext(log_name); uint length=(uint) (p-log_name); - strmake(buff,log_name,min(length,FN_REFLEN)); + strmake(buff, log_name, min(length, FN_REFLEN-1)); return (const char*)buff; } return log_name; @@ -1503,7 +1503,7 @@ int MYSQL_LOG::purge_logs_before_date(time_t purge_time) if (stat_area.st_mtime < purge_time) strmake(to_log, log_info.log_file_name, - sizeof(log_info.log_file_name)); + sizeof(log_info.log_file_name) - 1); else break; } @@ -2604,11 +2604,11 @@ bool flush_error_log() if (opt_error_log) { char err_renamed[FN_REFLEN], *end; - end= strmake(err_renamed,log_error_file,FN_REFLEN-4); + end= strmake(err_renamed,log_error_file,FN_REFLEN-5); strmov(end, "-old"); VOID(pthread_mutex_lock(&LOCK_error_log)); #ifdef __WIN__ - char err_temp[FN_REFLEN+4]; + char err_temp[FN_REFLEN+5]; /* On Windows is necessary a temporary file for to rename the current error file. diff --git a/sql/sp_pcontext.h b/sql/sp_pcontext.h index db8bed349f2..cd3011b2c37 100644 --- a/sql/sp_pcontext.h +++ b/sql/sp_pcontext.h @@ -71,7 +71,7 @@ typedef struct sp_label typedef struct sp_cond_type { enum { number, state, warning, notfound, exception } type; - char sqlstate[6]; + char sqlstate[SQLSTATE_LENGTH+1]; uint mysqlerr; } sp_cond_type_t; diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index f29baad9a84..bf117874552 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -914,7 +914,7 @@ int acl_getroot(THD *thd, USER_RESOURCES *mqh, *mqh= acl_user->user_resource; if (acl_user->host.hostname) - strmake(sctx->priv_host, acl_user->host.hostname, MAX_HOSTNAME); + strmake(sctx->priv_host, acl_user->host.hostname, MAX_HOSTNAME - 1); else *sctx->priv_host= 0; } @@ -1015,7 +1015,7 @@ bool acl_getroot_no_password(Security_context *sctx, char *user, char *host, sctx->priv_user= acl_user->user ? user : (char *) ""; if (acl_user->host.hostname) - strmake(sctx->priv_host, acl_user->host.hostname, MAX_HOSTNAME); + strmake(sctx->priv_host, acl_user->host.hostname, MAX_HOSTNAME - 1); else *sctx->priv_host= 0; } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index f34aa3c3bad..48df40f2614 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -917,7 +917,7 @@ static int check_connection(THD *thd) vio_keepalive(net->vio, TRUE); { /* buff[] needs to big enough to hold the server_version variable */ - char buff[SERVER_VERSION_LENGTH + SCRAMBLE_LENGTH + 64]; + char buff[SERVER_VERSION_LENGTH + 1 + SCRAMBLE_LENGTH + 1 + 64]; ulong client_flags = (CLIENT_LONG_FLAG | CLIENT_CONNECT_WITH_DB | CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index e32c17bc678..9432c5c3f89 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -742,7 +742,7 @@ static int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, !(sql_field->charset= get_charset_by_csname(sql_field->charset->csname, MY_CS_BINSORT,MYF(0)))) { - char tmp[64]; + char tmp[65]; strmake(strmake(tmp, save_cs->csname, sizeof(tmp)-4), STRING_WITH_LEN("_bin")); my_error(ER_UNKNOWN_COLLATION, MYF(0), tmp); -- cgit v1.2.1 From 5f3b645b1e8568e42358be5bc327920ad3b57c97 Mon Sep 17 00:00:00 2001 From: Magne Mahre Date: Fri, 18 Dec 2009 11:48:34 +0100 Subject: Backport to 5.1 branch (next-mr revid: 2921) Bug#35589 SET PASSWORD caused a crash Bug#35591 FLUSH PRIVILEGES caused a crash A race condition on the privilege hash tables (proc_priv_hash and func_priv_hash) caused one thread to try to delete elements that had already been deleted by another thread. The bug was caused by reading and saving the pointers to the hash tables outside mutex protection. This led to an inconsistency where a thread copied a pointer to a hash, another thread did the same, the first thread then deleted the hash, and the second then crashed when it in turn tried to delete the deleted hash. The fix is to ensure that operations on the shared hash structures happens under mutex protection (moving the locking up a little) --- sql/sql_acl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 3b81a85c368..b30c012e633 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -3765,11 +3765,11 @@ static my_bool grant_reload_procs_priv(THD *thd) DBUG_RETURN(TRUE); } + rw_wrlock(&LOCK_grant); /* Save a copy of the current hash if we need to undo the grant load */ old_proc_priv_hash= proc_priv_hash; old_func_priv_hash= func_priv_hash; - rw_wrlock(&LOCK_grant); if ((return_val= grant_load_procs_priv(table.table))) { /* Error; Reverting to old hash */ -- cgit v1.2.1 From 2887dd45b73e74d0f71ac2fc8641ee7f87237803 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Fri, 18 Dec 2009 17:14:09 -0200 Subject: Bug#48983: Bad strmake calls (length one too long) MySQL 5.1 specific fixes. --- server-tools/instance-manager/instance_map.cc | 4 ++-- server-tools/instance-manager/options.cc | 4 ++-- server-tools/instance-manager/user_map.cc | 2 +- sql/sql_plugin.cc | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server-tools/instance-manager/instance_map.cc b/server-tools/instance-manager/instance_map.cc index b137370b50a..a923c186b5d 100644 --- a/server-tools/instance-manager/instance_map.cc +++ b/server-tools/instance-manager/instance_map.cc @@ -117,13 +117,13 @@ static void parse_option(const char *option_str, while (*ptr == '-') ++ptr; - strmake(option_name_buf, ptr, MAX_OPTION_LEN + 1); + strmake(option_name_buf, ptr, MAX_OPTION_LEN); eq_pos= strchr(ptr, '='); if (eq_pos) { option_name_buf[eq_pos - ptr]= 0; - strmake(option_value_buf, eq_pos + 1, MAX_OPTION_LEN + 1); + strmake(option_value_buf, eq_pos + 1, MAX_OPTION_LEN); } else { diff --git a/server-tools/instance-manager/options.cc b/server-tools/instance-manager/options.cc index ebca593bb03..6e401bf3ffe 100644 --- a/server-tools/instance-manager/options.cc +++ b/server-tools/instance-manager/options.cc @@ -533,10 +533,10 @@ static int setup_windows_defaults() return 1; } - strmake(base_name, base_name_ptr, FN_REFLEN); + strmake(base_name, base_name_ptr, FN_REFLEN - 1); *base_name_ptr= 0; - strmake(im_name, base_name, FN_REFLEN); + strmake(im_name, base_name, FN_REFLEN - 1); ptr= strrchr(im_name, '.'); if (!ptr) diff --git a/server-tools/instance-manager/user_map.cc b/server-tools/instance-manager/user_map.cc index 49c35c16ca9..85e3f4a2cac 100644 --- a/server-tools/instance-manager/user_map.cc +++ b/server-tools/instance-manager/user_map.cc @@ -25,7 +25,7 @@ User::User(const LEX_STRING *user_name_arg, const char *password) { user_length= (uint8) (strmake(user, user_name_arg->str, - USERNAME_LENGTH + 1) - user); + USERNAME_LENGTH) - user); set_password(password); } diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index bafc601d142..9e35e392d2a 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -2084,7 +2084,7 @@ static int check_func_set(THD *thd, struct st_mysql_sys_var *var, &error, &error_len, ¬_used); if (error_len) { - strmake(buff, error, min(sizeof(buff), error_len)); + strmake(buff, error, min(sizeof(buff) - 1, error_len)); strvalue= buff; goto err; } -- cgit v1.2.1 From 885523381fc5e0f56a25c9a1f6671a55fd93a239 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Fri, 18 Dec 2009 18:32:55 -0200 Subject: Bug#30331: Table_locks_waited shows inaccurate values Post-merge fix: wait for statement result before disconnecting. Otherwise, the statement might affect unrelated tests. --- mysql-test/t/lock_multi.test | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mysql-test/t/lock_multi.test b/mysql-test/t/lock_multi.test index 47b5aa0292b..4df1a0f3478 100644 --- a/mysql-test/t/lock_multi.test +++ b/mysql-test/t/lock_multi.test @@ -626,9 +626,11 @@ let $wait_condition= --source include/wait_condition.inc let $tlwb= `show status like 'Table_locks_waited'`; unlock tables; +connection waiter; +--reap +connection default; drop table t1; disconnect waiter; -connection default; --disable_query_log eval SET @tlwa= SUBSTRING_INDEX('$tlwa', ' ', -1); eval SET @tlwb= SUBSTRING_INDEX('$tlwb', ' ', -1); -- cgit v1.2.1 From ff6c429612b8a4250f9b6a28a4e5660f44a1480b Mon Sep 17 00:00:00 2001 From: Staale Smedseng Date: Sun, 20 Dec 2009 19:02:15 +0100 Subject: Bug#43397 mysql headers redefine pthread_mutex_init unnecessarily Changing an instance of the define that was missed in the original commit due to the fact that it was misspelled. --- include/config-win.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/config-win.h b/include/config-win.h index af4915440b1..da9b1fc00c3 100644 --- a/include/config-win.h +++ b/include/config-win.h @@ -160,7 +160,7 @@ typedef uint rf_SetTimer; #define isnan(X) _isnan(X) #define finite(X) _finite(X) -#ifndef UNDEF_THREAD_HACK +#ifndef MYSQL_CLIENT_NO_THREADS #define THREAD #endif #define VOID_SIGHANDLER -- cgit v1.2.1 From d332a1895282aa7b3786b8116ad89d93db8ddd6a Mon Sep 17 00:00:00 2001 From: He Zhenxing Date: Mon, 21 Dec 2009 14:14:45 +0800 Subject: Bug#47638 The rpl_killed_ddl test fails on Windows When the $diff_statement variable for diff_master_slave.inc was put in multiple lines, the rear part of the statement would be missing when being executed on Windows systems. Fixed the problem by always putting the value for $diff_statement in one line. --- mysql-test/suite/rpl/t/rpl_killed_ddl.test | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mysql-test/suite/rpl/t/rpl_killed_ddl.test b/mysql-test/suite/rpl/t/rpl_killed_ddl.test index 0f2fe5b60fb..61b882efcf3 100644 --- a/mysql-test/suite/rpl/t/rpl_killed_ddl.test +++ b/mysql-test/suite/rpl/t/rpl_killed_ddl.test @@ -158,8 +158,7 @@ source include/kill_query_and_diff_master_slave.inc; ######## EVENT ######## -let $diff_statement= SELECT event_name, event_body, execute_at - FROM information_schema.events where event_name like 'e%'; +let $diff_statement= SELECT event_name, event_body, execute_at FROM information_schema.events where event_name like 'e%'; send CREATE EVENT e2 ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 DAY -- cgit v1.2.1