From 53bc4d51644f36b3ece5c2401848cc128dbd8c24 Mon Sep 17 00:00:00 2001 From: "bar@mysql.com" <> Date: Thu, 18 May 2006 12:21:13 +0500 Subject: [PATCH 1/2] Bug#19392 Rename Database: Crash if case change Problem: Renaming a database to itself crashed server. It hapenned because of wrong DBUG_ASSERT. Fix: removing wrong DBUG_ASSERT. Now it reports a correct error message "database alreadt exists". --- mysql-test/r/renamedb.result | 4 ++++ mysql-test/t/renamedb.test | 8 ++++++++ sql/sql_db.cc | 6 +++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/renamedb.result b/mysql-test/r/renamedb.result index 26ae42e72aa..b22322fbe8d 100644 --- a/mysql-test/r/renamedb.result +++ b/mysql-test/r/renamedb.result @@ -27,3 +27,7 @@ a 2 3 drop database testdb2; +create database testdb1; +rename database testdb1 to testdb1; +ERROR HY000: Can't create database 'testdb1'; database exists +drop database testdb1; diff --git a/mysql-test/t/renamedb.test b/mysql-test/t/renamedb.test index 5cfb2ce0c12..1e71adb3bf3 100644 --- a/mysql-test/t/renamedb.test +++ b/mysql-test/t/renamedb.test @@ -16,3 +16,11 @@ select database(); show tables; select a from t1 order by a; drop database testdb2; + +# +# Bug#19392 Rename Database: Crash if case change +# +create database testdb1; +--error 1007 +rename database testdb1 to testdb1; +drop database testdb1; diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 3d035359b6f..cb43bb77def 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -134,9 +134,9 @@ void lock_db_delete(const char *name, uint length) { my_dblock_t *opt; safe_mutex_assert_owner(&LOCK_lock_db); - opt= (my_dblock_t *)hash_search(&lock_db_cache, (const byte*) name, length); - DBUG_ASSERT(opt != NULL); - hash_delete(&lock_db_cache, (byte*) opt); + if (opt= (my_dblock_t *)hash_search(&lock_db_cache, + (const byte*) name, length)) + hash_delete(&lock_db_cache, (byte*) opt); } From bcb2ceec7171ba8b42567a3c1b893c34d0054542 Mon Sep 17 00:00:00 2001 From: "bar@mysql.com" <> Date: Thu, 18 May 2006 12:28:39 +0500 Subject: [PATCH 2/2] sql_db.cc: Bug#19392: Rename Database: Crash if case change Additional minor fix, to avoid compiler warnings. --- sql/sql_db.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/sql_db.cc b/sql/sql_db.cc index cb43bb77def..ca34d80b225 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -134,8 +134,8 @@ void lock_db_delete(const char *name, uint length) { my_dblock_t *opt; safe_mutex_assert_owner(&LOCK_lock_db); - if (opt= (my_dblock_t *)hash_search(&lock_db_cache, - (const byte*) name, length)) + if ((opt= (my_dblock_t *)hash_search(&lock_db_cache, + (const byte*) name, length))) hash_delete(&lock_db_cache, (byte*) opt); }