From de9909faec7ae81b7946f314b97ff2da8be7fe2e Mon Sep 17 00:00:00 2001 From: "jimw@mysql.com" <> Date: Thu, 7 Jul 2005 11:49:44 -0700 Subject: [PATCH 1/4] Fix crash caused by calling DES_ENCRYPT() without the --des-key-file option having been passed to the server. (Bug #11643) --- BitKeeper/etc/config | 2 +- mysql-test/r/func_des_encrypt.result | 3 +++ mysql-test/t/func_des_encrypt.test | 9 +++++++++ sql/des_key_file.cc | 18 ++++++++++++------ sql/item_strfunc.cc | 11 +++++++++++ sql/mysql_priv.h | 1 + 6 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 mysql-test/r/func_des_encrypt.result create mode 100644 mysql-test/t/func_des_encrypt.test diff --git a/BitKeeper/etc/config b/BitKeeper/etc/config index c609fcdbd49..f1e8e29fbfb 100644 --- a/BitKeeper/etc/config +++ b/BitKeeper/etc/config @@ -24,7 +24,7 @@ description: MySQL - fast and reliable SQL database # repository is commercial it can be an internal email address or "none" # to disable logging. # -logging: logging@openlogging.org +logging: none # # If this field is set, all checkins will appear to be made by this user, # in effect making this a single user package. Single user packages are diff --git a/mysql-test/r/func_des_encrypt.result b/mysql-test/r/func_des_encrypt.result new file mode 100644 index 00000000000..46b30bdab58 --- /dev/null +++ b/mysql-test/r/func_des_encrypt.result @@ -0,0 +1,3 @@ +select des_encrypt('hello'); +des_encrypt('hello') +€Ö2nV“Ø} diff --git a/mysql-test/t/func_des_encrypt.test b/mysql-test/t/func_des_encrypt.test new file mode 100644 index 00000000000..201a0051c58 --- /dev/null +++ b/mysql-test/t/func_des_encrypt.test @@ -0,0 +1,9 @@ +-- source include/have_openssl.inc + +# This test can't be in func_encrypt.test, because it requires +# --des-key-file to not be set. + +# +# Bug #11643: des_encrypt() causes server to die +# +select des_encrypt('hello'); diff --git a/sql/des_key_file.cc b/sql/des_key_file.cc index c6b4c5f2c34..558e3f16ad2 100644 --- a/sql/des_key_file.cc +++ b/sql/des_key_file.cc @@ -22,7 +22,17 @@ struct st_des_keyschedule des_keyschedule[10]; uint des_default_key; pthread_mutex_t LOCK_des_key_file; -static int initialized; +static int initialized= 0; + +void +init_des_key_file() +{ + if (!initialized) + { + initialized=1; + pthread_mutex_init(&LOCK_des_key_file,MY_MUTEX_INIT_FAST); + } +} /* Function which loads DES keys from plaintext file into memory on MySQL @@ -45,11 +55,7 @@ load_des_key_file(const char *file_name) DBUG_ENTER("load_des_key_file"); DBUG_PRINT("enter",("name: %s",file_name)); - if (!initialized) - { - initialized=1; - pthread_mutex_init(&LOCK_des_key_file,MY_MUTEX_INIT_FAST); - } + init_des_key_file(); VOID(pthread_mutex_lock(&LOCK_des_key_file)); if ((file=my_open(file_name,O_RDONLY | O_BINARY ,MYF(MY_WME))) < 0 || diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 881a8a7c915..7fb27470b8e 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -388,6 +388,9 @@ String *Item_func_des_encrypt::val_str(String *str) if (arg_count == 1) { + /* Make sure LOCK_des_key_file was initialized. */ + init_des_key_file(); + /* Protect against someone doing FLUSH DES_KEY_FILE */ VOID(pthread_mutex_lock(&LOCK_des_key_file)); keyschedule= des_keyschedule[key_number=des_default_key]; @@ -398,6 +401,10 @@ String *Item_func_des_encrypt::val_str(String *str) key_number= (uint) args[1]->val_int(); if (key_number > 9) goto error; + + /* Make sure LOCK_des_key_file was initialized. */ + init_des_key_file(); + VOID(pthread_mutex_lock(&LOCK_des_key_file)); keyschedule= des_keyschedule[key_number]; VOID(pthread_mutex_unlock(&LOCK_des_key_file)); @@ -485,6 +492,10 @@ String *Item_func_des_decrypt::val_str(String *str) // Check if automatic key and that we have privilege to uncompress using it if (!(current_thd->master_access & SUPER_ACL) || key_number > 9) goto error; + + /* Make sure LOCK_des_key_file was initialized. */ + init_des_key_file(); + VOID(pthread_mutex_lock(&LOCK_des_key_file)); keyschedule= des_keyschedule[key_number]; VOID(pthread_mutex_unlock(&LOCK_des_key_file)); diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index cc58e34d582..5c97269b5ce 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -624,6 +624,7 @@ extern char *des_key_file; extern struct st_des_keyschedule des_keyschedule[10]; extern uint des_default_key; extern pthread_mutex_t LOCK_des_key_file; +void init_des_key_file(); bool load_des_key_file(const char *file_name); void free_des_key_file(); #endif /* HAVE_OPENSSL */ From 7ae4a6043c074235fc944e7fba25b903d5a17bb8 Mon Sep 17 00:00:00 2001 From: "jimw@mysql.com" <> Date: Mon, 11 Jul 2005 10:37:21 -0700 Subject: [PATCH 2/4] Apply security patch to bundled zlib for CAN-2005-2096. (Bug #11844) --- zlib/inftrees.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zlib/inftrees.c b/zlib/inftrees.c index 8a896b28793..509461d9273 100644 --- a/zlib/inftrees.c +++ b/zlib/inftrees.c @@ -134,7 +134,7 @@ unsigned short FAR *work; left -= count[len]; if (left < 0) return -1; /* over-subscribed */ } - if (left > 0 && (type == CODES || (codes - count[0] != 1))) + if (left > 0 && (type == CODES || max != 1)) return -1; /* incomplete set */ /* generate offsets into symbol table for each length for sorting */ From dc55af92ffee58f45f9c53cbeda7ca34931f2f74 Mon Sep 17 00:00:00 2001 From: "lars@mysql.com" <> Date: Tue, 12 Jul 2005 06:01:26 +0200 Subject: [PATCH 3/4] BUG#6987: Added note when stat is failing on relay log, added mutex for log rotatation. --- sql/log.cc | 2 ++ sql/slave.cc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/sql/log.cc b/sql/log.cc index c8a3b512b6d..a67f35e30bf 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -853,6 +853,8 @@ int MYSQL_LOG::purge_logs(const char *to_log, of space that deletion will free. In most cases, deletion won't work either, so it's not a problem. */ + sql_print_information("Failed to execute my_stat on file '%s'", + log_info.log_file_name); tmp= 0; } } diff --git a/sql/slave.cc b/sql/slave.cc index 5a2d3af3845..68769fc1f98 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -4462,6 +4462,7 @@ void rotate_relay_log(MASTER_INFO* mi) RELAY_LOG_INFO* rli= &mi->rli; lock_slave_threads(mi); + pthread_mutex_lock(&mi->data_lock); pthread_mutex_lock(&rli->data_lock); /* We need to test inited because otherwise, new_file() will attempt to lock @@ -4492,6 +4493,7 @@ void rotate_relay_log(MASTER_INFO* mi) rli->relay_log.harvest_bytes_written(&rli->log_space_total); end: pthread_mutex_unlock(&rli->data_lock); + pthread_mutex_unlock(&mi->data_lock); unlock_slave_threads(mi); DBUG_VOID_RETURN; } From c31d71c065304b7cd1c237174da19a8d4270fb26 Mon Sep 17 00:00:00 2001 From: "reggie@linux.site" <> Date: Tue, 12 Jul 2005 10:31:09 -0600 Subject: [PATCH 4/4] Fixed some vio code that was using ___WIN__ instead of __WIN__ --- include/my_global.h | 2 +- sql/net_serv.cc | 2 +- vio/vio.c | 4 ++-- vio/viosocket.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/my_global.h b/include/my_global.h index a7e6bba82b6..eab6050d2dc 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -797,7 +797,7 @@ typedef off_t os_off_t; #define socket_errno WSAGetLastError() #define SOCKET_EINTR WSAEINTR #define SOCKET_EAGAIN WSAEINPROGRESS -#define SOCKET_EWOULDBLOCK WSAEINPROGRESS +#define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK #define SOCKET_ENFILE ENFILE #define SOCKET_EMFILE EMFILE #elif defined(OS2) diff --git a/sql/net_serv.cc b/sql/net_serv.cc index bd4505a3d7f..9d84d0b2427 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -132,7 +132,7 @@ my_bool my_net_init(NET *net, Vio* vio) if (vio != 0) /* If real connection */ { net->fd = vio_fd(vio); /* For perl DBI/DBD */ -#if defined(MYSQL_SERVER) && !defined(___WIN__) && !defined(__EMX__) && !defined(OS2) +#if defined(MYSQL_SERVER) && !defined(__WIN__) && !defined(__EMX__) && !defined(OS2) if (!(test_flags & TEST_BLOCKING)) { my_bool old_mode; diff --git a/vio/vio.c b/vio/vio.c index 978780d2632..4660efe3048 100644 --- a/vio/vio.c +++ b/vio/vio.c @@ -130,7 +130,7 @@ Vio *vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost) sprintf(vio->desc, (vio->type == VIO_TYPE_SOCKET ? "socket (%d)" : "TCP/IP (%d)"), vio->sd); -#if !defined(___WIN__) && !defined(__EMX__) && !defined(OS2) +#if !defined(__WIN__) && !defined(__EMX__) && !defined(OS2) #if !defined(NO_FCNTL_NONBLOCK) #if defined(__FreeBSD__) fcntl(sd, F_SETFL, vio->fcntl_mode); /* Yahoo! FreeBSD patch */ @@ -145,7 +145,7 @@ Vio *vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost) { /* set to blocking mode by default */ ulong arg=0, r; - r = ioctlsocket(sd,FIONBIO,(void*) &arg, sizeof(arg)); + r = ioctlsocket(sd,FIONBIO,(void*) &arg); vio->fcntl_mode &= ~O_NONBLOCK; } #endif diff --git a/vio/viosocket.c b/vio/viosocket.c index 904b75583a9..c7561890ead 100644 --- a/vio/viosocket.c +++ b/vio/viosocket.c @@ -82,7 +82,7 @@ int vio_blocking(Vio * vio __attribute__((unused)), my_bool set_blocking_mode, DBUG_PRINT("enter", ("set_blocking_mode: %d old_mode: %d", (int) set_blocking_mode, (int) *old_mode)); -#if !defined(___WIN__) && !defined(__EMX__) +#if !defined(__WIN__) && !defined(__EMX__) #if !defined(NO_FCNTL_NONBLOCK) if (vio->sd >= 0) { @@ -115,7 +115,7 @@ int vio_blocking(Vio * vio __attribute__((unused)), my_bool set_blocking_mode, vio->fcntl_mode |= O_NONBLOCK; /* set bit */ } if (old_fcntl != vio->fcntl_mode) - r = ioctlsocket(vio->sd,FIONBIO,(void*) &arg, sizeof(arg)); + r = ioctlsocket(vio->sd,FIONBIO,(void*) &arg); } #ifndef __EMX__ else