summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/grant.result26
-rw-r--r--mysql-test/t/grant.test40
-rw-r--r--sql/sql_acl.cc4
3 files changed, 68 insertions, 2 deletions
diff --git a/mysql-test/r/grant.result b/mysql-test/r/grant.result
index 399f8964c2f..94087393489 100644
--- a/mysql-test/r/grant.result
+++ b/mysql-test/r/grant.result
@@ -2560,3 +2560,29 @@ Grants for mysqltest_u1@%
GRANT USAGE ON *.* TO 'mysqltest_u1'@'%'
drop database mysqltest_db1;
drop user mysqltest_u1;
+#
+# Bug#12766319 - 61865: RENAME USER DOES NOT WORK CORRECTLY -
+# REQUIRES FLUSH PRIVILEGES
+#
+CREATE USER foo@'127.0.0.1';
+GRANT ALL ON *.* TO foo@'127.0.0.1';
+# First attempt, should connect successfully
+SELECT user(), current_user();
+user() current_user()
+foo@localhost foo@127.0.0.1
+# Rename the user
+RENAME USER foo@'127.0.0.1' to foo@'127.0.0.0/255.0.0.0';
+# Second attempt, should connect successfully as its valid mask
+# This was failing without fix
+SELECT user(), current_user();
+user() current_user()
+foo@localhost foo@127.0.0.0/255.0.0.0
+# Rename the user back to original
+RENAME USER foo@'127.0.0.0/255.0.0.0' to foo@'127.0.0.1';
+# Third attempt, should connect successfully
+SELECT user(), current_user();
+user() current_user()
+foo@localhost foo@127.0.0.1
+# Clean-up
+DROP USER foo@'127.0.0.1';
+# End of Bug#12766319
diff --git a/mysql-test/t/grant.test b/mysql-test/t/grant.test
index 7a8fb0598d1..efa79c5b768 100644
--- a/mysql-test/t/grant.test
+++ b/mysql-test/t/grant.test
@@ -2211,3 +2211,43 @@ grant select on mysqltest_db1.t1 to mysqltest_u1;
show grants for mysqltest_u1;
drop database mysqltest_db1;
drop user mysqltest_u1;
+
+
+--echo #
+--echo # Bug#12766319 - 61865: RENAME USER DOES NOT WORK CORRECTLY -
+--echo # REQUIRES FLUSH PRIVILEGES
+--echo #
+
+CREATE USER foo@'127.0.0.1';
+GRANT ALL ON *.* TO foo@'127.0.0.1';
+
+--echo # First attempt, should connect successfully
+connect (conn1, '127.0.0.1', foo,,test);
+SELECT user(), current_user();
+
+--echo # Rename the user
+RENAME USER foo@'127.0.0.1' to foo@'127.0.0.0/255.0.0.0';
+
+--echo # Second attempt, should connect successfully as its valid mask
+--echo # This was failing without fix
+connect (conn2, '127.0.0.1', foo,,test);
+SELECT user(), current_user();
+
+--echo # Rename the user back to original
+RENAME USER foo@'127.0.0.0/255.0.0.0' to foo@'127.0.0.1';
+
+--echo # Third attempt, should connect successfully
+connect (conn3, '127.0.0.1', foo,,test);
+SELECT user(), current_user();
+
+--echo # Clean-up
+connection default;
+disconnect conn1;
+disconnect conn2;
+disconnect conn3;
+DROP USER foo@'127.0.0.1';
+
+--echo # End of Bug#12766319
+
+# Wait till we reached the initial number of concurrent sessions
+--source include/wait_until_count_sessions.inc
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index 0a1c11ef97a..03f0e878db6 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -6285,12 +6285,12 @@ static int handle_grant_struct(enum enum_acl_lists struct_no, bool drop,
switch ( struct_no ) {
case USER_ACL:
acl_user->user= strdup_root(&mem, user_to->user.str);
- acl_user->host.hostname= strdup_root(&mem, user_to->host.str);
+ update_hostname(&acl_user->host, strdup_root(&mem, user_to->host.str));
break;
case DB_ACL:
acl_db->user= strdup_root(&mem, user_to->user.str);
- acl_db->host.hostname= strdup_root(&mem, user_to->host.str);
+ update_hostname(&acl_db->host, strdup_root(&mem, user_to->host.str));
break;
case COLUMN_PRIVILEGES_HASH: