From 9fc25141a20bdbd0d467f7115309954959f985f7 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Apr 2006 18:06:43 +0400 Subject: [PATCH 1/4] Bug#16501: IS_USED_LOCK does not appear to work Update User_level_lock::thread_id on acquiring an existing lock, and reset it on lock release. mysql-test/r/func_misc.result: Add result for bug#16501. mysql-test/t/func_misc.test: Add test case for bug#16501. sql/item_func.cc: Update User_level_lock::thread_id on acquiring an existing lock, and reset it on lock release (for safety). --- mysql-test/r/func_misc.result | 36 +++++++++++++++++++++++++++++++++ mysql-test/t/func_misc.test | 38 +++++++++++++++++++++++++++++++++++ sql/item_func.cc | 2 ++ 3 files changed, 76 insertions(+) diff --git a/mysql-test/r/func_misc.result b/mysql-test/r/func_misc.result index 181ecf7b65b..a5beef859f0 100644 --- a/mysql-test/r/func_misc.result +++ b/mysql-test/r/func_misc.result @@ -57,3 +57,39 @@ t1 CREATE TABLE `t1` ( `length(uuid())` int(10) NOT NULL default '0' ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (conn CHAR(7), connection_id INT); +INSERT INTO t1 VALUES ('default', CONNECTION_ID()); +SELECT GET_LOCK('bug16501',600); +GET_LOCK('bug16501',600) +1 +INSERT INTO t1 VALUES ('con1', CONNECTION_ID()); +SELECT IS_USED_LOCK('bug16501') = connection_id +FROM t1 +WHERE conn = 'default'; +IS_USED_LOCK('bug16501') = connection_id +1 + SELECT GET_LOCK('bug16501',600); +SELECT IS_USED_LOCK('bug16501') = CONNECTION_ID(); +IS_USED_LOCK('bug16501') = CONNECTION_ID() +1 +SELECT RELEASE_LOCK('bug16501'); +RELEASE_LOCK('bug16501') +1 +SELECT IS_USED_LOCK('bug16501') = connection_id +FROM t1 +WHERE conn = 'con1'; +IS_USED_LOCK('bug16501') = connection_id +1 +GET_LOCK('bug16501',600) +1 +SELECT IS_USED_LOCK('bug16501') = CONNECTION_ID(); +IS_USED_LOCK('bug16501') = CONNECTION_ID() +1 +SELECT RELEASE_LOCK('bug16501'); +RELEASE_LOCK('bug16501') +1 +SELECT IS_USED_LOCK('bug16501'); +IS_USED_LOCK('bug16501') +NULL +DROP TABLE t1; diff --git a/mysql-test/t/func_misc.test b/mysql-test/t/func_misc.test index 87d9d601c87..9c706161ba9 100644 --- a/mysql-test/t/func_misc.test +++ b/mysql-test/t/func_misc.test @@ -43,4 +43,42 @@ create table t1 as select uuid(), length(uuid()); show create table t1; drop table t1; + +# +# Bug#16501: IS_USED_LOCK does not appear to work +# +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (conn CHAR(7), connection_id INT); +INSERT INTO t1 VALUES ('default', CONNECTION_ID()); + +SELECT GET_LOCK('bug16501',600); + +connect (con1,localhost,root,,); +INSERT INTO t1 VALUES ('con1', CONNECTION_ID()); +SELECT IS_USED_LOCK('bug16501') = connection_id +FROM t1 +WHERE conn = 'default'; +send SELECT GET_LOCK('bug16501',600); + +connection default; +SELECT IS_USED_LOCK('bug16501') = CONNECTION_ID(); +SELECT RELEASE_LOCK('bug16501'); +SELECT IS_USED_LOCK('bug16501') = connection_id +FROM t1 +WHERE conn = 'con1'; + +connection con1; +reap; +SELECT IS_USED_LOCK('bug16501') = CONNECTION_ID(); +SELECT RELEASE_LOCK('bug16501'); +SELECT IS_USED_LOCK('bug16501'); + +disconnect con1; +connection default; + +DROP TABLE t1; + # End of 4.1 tests diff --git a/sql/item_func.cc b/sql/item_func.cc index 174a8c55d01..1f170242113 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1972,6 +1972,7 @@ void item_user_lock_free(void) void item_user_lock_release(User_level_lock *ull) { ull->locked=0; + ull->thread_id= 0; if (mysql_bin_log.is_open()) { char buf[256]; @@ -2170,6 +2171,7 @@ longlong Item_func_get_lock::val_int() { ull->locked=1; ull->thread=thd->real_id; + ull->thread_id= thd->thread_id; thd->ull=ull; error=0; } From e89b442b6570ae4a4f44b863b4014d14a8090a84 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 27 Apr 2006 14:54:36 +0400 Subject: [PATCH 2/4] Bug#16372: Server crashes when test 'conc_sys' is running Concurrent read and update of privilege structures (like simultaneous run of SHOW GRANTS and ADD USER) could result in server crash. Ensure that proper locking of ACL structures is done. No test case is provided because this bug can't be reproduced deterministically. sql/sql_acl.cc: Ensure that access to ACL data is protected by acl_cache->lock mutex. Use system_charset_info for host names consistently. --- sql/sql_acl.cc | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 4626e5892a4..204a38dfb64 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -894,6 +894,8 @@ static void acl_update_user(const char *user, const char *host, USER_RESOURCES *mqh, ulong privileges) { + safe_mutex_assert_owner(&acl_cache->lock); + for (uint i=0 ; i < acl_users.elements ; i++) { ACL_USER *acl_user=dynamic_element(&acl_users,i,ACL_USER*); @@ -942,6 +944,9 @@ static void acl_insert_user(const char *user, const char *host, ulong privileges) { ACL_USER acl_user; + + safe_mutex_assert_owner(&acl_cache->lock); + acl_user.user=*user ? strdup_root(&mem,user) : 0; update_hostname(&acl_user.host, *host ? strdup_root(&mem, host): 0); acl_user.access=privileges; @@ -973,6 +978,8 @@ static void acl_insert_user(const char *user, const char *host, static void acl_update_db(const char *user, const char *host, const char *db, ulong privileges) { + safe_mutex_assert_owner(&acl_cache->lock); + for (uint i=0 ; i < acl_dbs.elements ; i++) { ACL_DB *acl_db=dynamic_element(&acl_dbs,i,ACL_DB*); @@ -1358,6 +1365,9 @@ find_acl_user(const char *host, const char *user, my_bool exact) { DBUG_ENTER("find_acl_user"); DBUG_PRINT("enter",("host: '%s' user: '%s'",host,user)); + + safe_mutex_assert_owner(&acl_cache->lock); + for (uint i=0 ; i < acl_users.elements ; i++) { ACL_USER *acl_user=dynamic_element(&acl_users,i,ACL_USER*); @@ -1370,7 +1380,7 @@ find_acl_user(const char *host, const char *user, my_bool exact) if (!acl_user->user && !user[0] || acl_user->user && !strcmp(user,acl_user->user)) { - if (exact ? !my_strcasecmp(&my_charset_latin1, host, + if (exact ? !my_strcasecmp(system_charset_info, host, acl_user->host.hostname ? acl_user->host.hostname : "") : compare_hostname(&acl_user->host,host,host)) @@ -2445,6 +2455,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, create_new_users= test_if_create_new_users(thd); int result=0; rw_wrlock(&LOCK_grant); + pthread_mutex_lock(&acl_cache->lock); MEM_ROOT *old_root= thd->mem_root; thd->mem_root= &memex; @@ -2460,10 +2471,8 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, continue; } /* Create user if needed */ - pthread_mutex_lock(&acl_cache->lock); error=replace_user_table(thd, tables[0].table, *Str, 0, revoke_grant, create_new_users); - pthread_mutex_unlock(&acl_cache->lock); if (error) { result= -1; // Remember error @@ -2552,6 +2561,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, } grant_option=TRUE; thd->mem_root= old_root; + pthread_mutex_unlock(&acl_cache->lock); rw_unlock(&LOCK_grant); if (!result) send_ok(thd); @@ -3203,6 +3213,9 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) DBUG_RETURN(-1); } + rw_rdlock(&LOCK_grant); + VOID(pthread_mutex_lock(&acl_cache->lock)); + for (counter=0 ; counter < acl_users.elements ; counter++) { const char *user,*host; @@ -3217,6 +3230,9 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) } if (counter == acl_users.elements) { + VOID(pthread_mutex_unlock(&acl_cache->lock)); + rw_unlock(&LOCK_grant); + my_error(ER_NONEXISTING_GRANT, MYF(0), lex_user->user.str, lex_user->host.str); DBUG_RETURN(-1); @@ -3230,10 +3246,12 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) lex_user->host.str,NullS); field_list.push_back(field); if (protocol->send_fields(&field_list,1)) - DBUG_RETURN(-1); + { + VOID(pthread_mutex_unlock(&acl_cache->lock)); + rw_unlock(&LOCK_grant); - rw_wrlock(&LOCK_grant); - VOID(pthread_mutex_lock(&acl_cache->lock)); + DBUG_RETURN(-1); + } /* Add first global access grants */ { @@ -3540,10 +3558,15 @@ void get_privilege_desc(char *to, uint max_length, ulong access) void get_mqh(const char *user, const char *host, USER_CONN *uc) { ACL_USER *acl_user; + + pthread_mutex_lock(&acl_cache->lock); + if (initialized && (acl_user= find_acl_user(host,user, FALSE))) uc->user_resources= acl_user->user_resource; else bzero((char*) &uc->user_resources, sizeof(uc->user_resources)); + + pthread_mutex_unlock(&acl_cache->lock); } int open_grant_tables(THD *thd, TABLE_LIST *tables) @@ -3602,6 +3625,8 @@ ACL_USER *check_acl_user(LEX_USER *user_name, ACL_USER *acl_user= 0; uint counter; + safe_mutex_assert_owner(&acl_cache->lock); + for (counter= 0 ; counter < acl_users.elements ; counter++) { const char *user,*host; From b8984be3b63a705b27e4e4e220b3e3fafc802b6c Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 4 May 2006 16:14:19 -0500 Subject: [PATCH 3/4] .del-changelog-4.0.xml~8f56ee8a913e848b: Delete: Docs/changelog-4.0.xml BitKeeper/deleted/.del-changelog-4.0.xml~8f56ee8a913e848b: Delete: Docs/changelog-4.0.xml --- Docs/changelog-4.0.xml | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100755 Docs/changelog-4.0.xml diff --git a/Docs/changelog-4.0.xml b/Docs/changelog-4.0.xml deleted file mode 100755 index f0f9aa881f1..00000000000 --- a/Docs/changelog-4.0.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - Changes in release 4.0.x - - - - This is a dummy changelog file. Don't use it yet. - - - From ac5eb33a42daf27e259624b115b39b9cf45c6e5f Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 4 May 2006 16:16:18 -0500 Subject: [PATCH 4/4] .del-changelog-4.1.xml~8aa496ebed09d868: Delete: Docs/changelog-4.1.xml BitKeeper/deleted/.del-changelog-4.1.xml~8aa496ebed09d868: Delete: Docs/changelog-4.1.xml --- Docs/changelog-4.1.xml | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100755 Docs/changelog-4.1.xml diff --git a/Docs/changelog-4.1.xml b/Docs/changelog-4.1.xml deleted file mode 100755 index 644f2940d0f..00000000000 --- a/Docs/changelog-4.1.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - Changes in release 4.1.x - - - - This is a dummy changelog file. Don't use it yet. - - -