diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 820701f844c..4142fc0b796 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -8032,3 +8032,13 @@ return 1; end | ERROR 0A000: Not allowed to return a result set from a function drop table t1,t2; +# +# 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; +#End of 10.1 tests diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index bcddbd6f97e..3034f34d763 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -9504,3 +9504,17 @@ end | --delimiter ; drop table t1,t2; + +--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; + + +--echo #End of 10.1 tests diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 3f26bc2e08a..2accb3abc91 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -1067,7 +1067,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);