From 20776a68d2e4f4a68af7380e1fa72a254ddcb56a Mon Sep 17 00:00:00 2001
From: Daniel Fischer <df@sun.com>
Date: Thu, 30 Apr 2009 12:57:03 +0200
Subject: [PATCH] backport #41456, commit 61847

---
 mysql-test/r/grant.result | 5 +++++
 mysql-test/t/grant.test   | 7 +++++++
 sql/set_var.cc            | 7 +++++++
 3 files changed, 19 insertions(+)

diff --git a/mysql-test/r/grant.result b/mysql-test/r/grant.result
index d56020c3090..ee328d461ac 100644
--- a/mysql-test/r/grant.result
+++ b/mysql-test/r/grant.result
@@ -1151,4 +1151,9 @@ drop user 'greg'@'localhost';
 drop view v1;
 drop table test;
 drop function test_function;
+SELECT CURRENT_USER();
+CURRENT_USER()
+root@localhost
+SET PASSWORD FOR CURRENT_USER() = PASSWORD("admin");
+SET PASSWORD FOR CURRENT_USER() = PASSWORD("");
 End of 5.0 tests
diff --git a/mysql-test/t/grant.test b/mysql-test/t/grant.test
index e4b95502143..14c5879d007 100644
--- a/mysql-test/t/grant.test
+++ b/mysql-test/t/grant.test
@@ -1175,4 +1175,11 @@ drop view v1;
 drop table test;
 drop function test_function;
 
+#
+# Bug#41456 SET PASSWORD hates CURRENT_USER()
+#
+SELECT CURRENT_USER();
+SET PASSWORD FOR CURRENT_USER() = PASSWORD("admin");
+SET PASSWORD FOR CURRENT_USER() = PASSWORD("");
+
 --echo End of 5.0 tests
diff --git a/sql/set_var.cc b/sql/set_var.cc
index 59741e5683d..a29abe6581f 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -3475,6 +3475,7 @@ int set_var_password::check(THD *thd)
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
   if (!user->host.str)
   {
+    DBUG_ASSERT(thd->security_ctx->priv_host);
     if (*thd->security_ctx->priv_host != 0)
     {
       user->host.str= (char *) thd->security_ctx->priv_host;
@@ -3486,6 +3487,12 @@ int set_var_password::check(THD *thd)
       user->host.length= 1;
     }
   }
+  if (!user->user.str)
+  {
+    DBUG_ASSERT(thd->security_ctx->priv_user);
+    user->user.str= (char *) thd->security_ctx->priv_user;
+    user->user.length= strlen(thd->security_ctx->priv_user);
+  }
   /* Returns 1 as the function sends error to client */
   return check_change_password(thd, user->host.str, user->user.str,
                                password, strlen(password)) ? 1 : 0;