From 100f721c0aeb96f687a658586afd22a67098c4a8 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Wed, 21 Dec 2016 17:41:48 +0100 Subject: [PATCH] MDEV-11584: GRANT inside an SP does not work well on 2nd execution Allocate password hash in statment memory --- mysql-test/r/sp.result | 9 +++++++++ mysql-test/t/sp.test | 11 +++++++++++ sql/sql_acl.cc | 5 +++++ 3 files changed, 25 insertions(+) diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index fefcdae539e..2b50585aa5b 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -8040,3 +8040,12 @@ v_name v_total c 1 DROP PROCEDURE p1; DROP TABLE t1; +# +# MDEV-11584: GRANT inside an SP does not work well on 2nd execution +# +CREATE PROCEDURE sp1() +GRANT ALL PRIVILEGES ON *.* TO 'foo'@'%' IDENTIFIED BY 'pass'; +CALL sp1(); +CALL sp1(); +drop user 'foo'@'%'; +drop procedure sp1; diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index aaab59bcb89..acb6099cea1 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -9484,3 +9484,14 @@ CALL p1(); DROP PROCEDURE p1; DROP TABLE t1; + +--echo # +--echo # MDEV-11584: GRANT inside an SP does not work well on 2nd execution +--echo # + +CREATE PROCEDURE sp1() + GRANT ALL PRIVILEGES ON *.* TO 'foo'@'%' IDENTIFIED BY 'pass'; +CALL sp1(); +CALL sp1(); +drop user 'foo'@'%'; +drop procedure sp1; diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 2ae252c2232..6334d3fa1dd 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -1064,7 +1064,12 @@ static bool fix_lex_user(THD *thd, LEX_USER *user) make_scramble= my_make_scrambled_password; } + Query_arena *arena, backup; + arena= thd->activate_stmt_arena_if_needed(&backup); char *buff= (char *) thd->alloc(scramble_length + 1); + if (arena) + thd->restore_active_arena(arena, &backup); + if (buff == NULL) return true; make_scramble(buff, user->pwtext.str, user->pwtext.length);