From fc0d9a470ce9ae2285f687e9b13f08b76527051b Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 9 Jan 2021 17:00:04 +0100 Subject: [PATCH] MDEV-22966 Server crashes or hangs with SET ROLE when started with skip-grant-tables --- mysql-test/r/skip_grants.result | 8 ++++++++ mysql-test/t/skip_grants.test | 11 +++++++++++ sql/sql_acl.cc | 6 ++++++ 3 files changed, 25 insertions(+) diff --git a/mysql-test/r/skip_grants.result b/mysql-test/r/skip_grants.result index b92e62a6ff0..b058c8f001e 100644 --- a/mysql-test/r/skip_grants.result +++ b/mysql-test/r/skip_grants.result @@ -99,3 +99,11 @@ Acl_users 0 # # End of 10.1 tests # +# +# MDEV-22966 Server crashes or hangs with SET ROLE when started with skip-grant-tables +# +set role x; +ERROR HY000: The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement +# +# End of 10.2 tests +# diff --git a/mysql-test/t/skip_grants.test b/mysql-test/t/skip_grants.test index f68734f8244..0ecaa022fd4 100644 --- a/mysql-test/t/skip_grants.test +++ b/mysql-test/t/skip_grants.test @@ -128,3 +128,14 @@ show global status like 'Acl%'; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # MDEV-22966 Server crashes or hangs with SET ROLE when started with skip-grant-tables +--echo # + +--error ER_OPTION_PREVENTS_STATEMENT +set role x; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 6aa53e50bae..f1034986f22 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -2770,6 +2770,12 @@ end: int acl_check_setrole(THD *thd, char *rolename, ulonglong *access) { + if (!initialized) + { + my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables"); + return 1; + } + return check_user_can_set_role(thd, thd->security_ctx->priv_user, thd->security_ctx->host, thd->security_ctx->ip, rolename, access); }