diff --git a/mysql-test/suite/roles/show_grants_anon-5238.result b/mysql-test/suite/roles/show_grants_anon-5238.result new file mode 100644 index 00000000000..85be1ac92f3 --- /dev/null +++ b/mysql-test/suite/roles/show_grants_anon-5238.result @@ -0,0 +1,12 @@ +create user ''@localhost; +create role r1; +grant r1 to ''@localhost; +select current_user; +current_user +@localhost +show grants; +Grants for @localhost +GRANT r1 TO ''@'localhost' +GRANT USAGE ON *.* TO ''@'localhost' +drop role r1; +drop user ''@localhost; diff --git a/mysql-test/suite/roles/show_grants_anon-5238.test b/mysql-test/suite/roles/show_grants_anon-5238.test new file mode 100644 index 00000000000..adb22490233 --- /dev/null +++ b/mysql-test/suite/roles/show_grants_anon-5238.test @@ -0,0 +1,17 @@ +# +# MDEV-5238 Server crashes in find_role_grant_pair on SHOW GRANTS for an anonymous user +# +--source include/not_embedded.inc + +create user ''@localhost; +create role r1; +grant r1 to ''@localhost; + +--connect (con1,localhost,nonexisting_user,,) +select current_user; +show grants; + +connection default; +drop role r1; +drop user ''@localhost; + diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index fd664e14208..3c88a3a4131 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -7556,7 +7556,7 @@ static ROLE_GRANT_PAIR *find_role_grant_pair(const LEX_STRING *u, pair_key.alloc(key_length); strmov(strmov(strmov(const_cast(pair_key.ptr()), - u->str) + 1, h->str) + 1, r->str); + safe_str(u->str)) + 1, h->str) + 1, r->str); return (ROLE_GRANT_PAIR *) my_hash_search(&acl_roles_mappings, (uchar*)pair_key.ptr(), key_length);