From e820762e8b4313ffd710e822796c87b42a103b99 Mon Sep 17 00:00:00 2001
From: David Gow <davidgow@google.com>
Date: Mon, 22 Feb 2016 13:05:55 -0800
Subject: [PATCH] Hacky fix for MDEV-9580: SHOW GRANTS should work for
 unadorned current user

Note that this does break the roles.show_grants test, by changing the
error reported on SHOW GRANTS FOR CURRENT_ROLE without a current role
existing.

Since we don't use roles, this is probably okay until a real fix comes
along.
---
 mysql-test/suite/roles/show_grants.result | 4 ++--
 mysql-test/suite/roles/show_grants.test   | 4 ++--
 mysql-test/t/grant6.test                  | 3 +++
 sql/sql_parse.cc                          | 1 +
 4 files changed, 8 insertions(+), 4 deletions(-)
 create mode 100644 mysql-test/t/grant6.test

diff --git a/mysql-test/suite/roles/show_grants.result b/mysql-test/suite/roles/show_grants.result
index e7b7860..0e2bc99 100644
--- a/mysql-test/suite/roles/show_grants.result
+++ b/mysql-test/suite/roles/show_grants.result
@@ -89,9 +89,9 @@ GRANT USAGE ON *.* TO 'test_user'@'localhost'
 GRANT test_role1 TO 'test_user'@'localhost'
 GRANT test_role2 TO 'test_user'@'localhost'
 show grants for CURRENT_ROLE;
-ERROR 42000: There is no such grant defined for user 'test_user' on host 'localhost'
+ERROR 0L000: Invalid definer
 show grants for CURRENT_ROLE();
-ERROR 42000: There is no such grant defined for user 'test_user' on host 'localhost'
+ERROR 0L000: Invalid definer
 set role test_role2;
 select * from information_schema.enabled_roles;
 ROLE_NAME
diff --git a/mysql-test/suite/roles/show_grants.test b/mysql-test/suite/roles/show_grants.test
index 9c15d8b..b565f4f 100644
--- a/mysql-test/suite/roles/show_grants.test
+++ b/mysql-test/suite/roles/show_grants.test
@@ -53,9 +53,9 @@ show grants for test_role2;
 show grants for CURRENT_USER;
 --sorted_result
 show grants for CURRENT_USER();
---error ER_NONEXISTING_GRANT
+--error ER_MALFORMED_DEFINER
 show grants for CURRENT_ROLE;
---error ER_NONEXISTING_GRANT
+--error ER_MALFORMED_DEFINER
 show grants for CURRENT_ROLE();
 
 set role test_role2;
diff --git a/mysql-test/t/grant6.test b/mysql-test/t/grant6.test
new file mode 100644
index 0000000..de2ee96
--- /dev/null
+++ b/mysql-test/t/grant6.test
@@ -0,0 +1,3 @@
+CREATE USER test;
+connect (conn_1, localhost, test,,);
+SHOW GRANTS FOR test;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 8373dda..6ce9a2c 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -4375,6 +4375,7 @@ case SQLCOM_PREPARE:
   {
     LEX_USER *grant_user= lex->grant_user;
     Security_context *sctx= thd->security_ctx;
+    grant_user = get_current_user(thd, grant_user);
     if (!grant_user)
       goto error;
 
-- 
2.7.0.rc3.207.g0ac5344

