Skip to content

Commit

Permalink
MDEV-11533: Roles with trailing white spaces are not cleared correctly
Browse files Browse the repository at this point in the history
Role names with trailing whitespaces are truncated in length as of
956e92d to fix MDEV-8609. The problem
is that the code that creates role mappings expects the string to be null
terminated.

Add the null terminator to account for that as well. In the future
the rest of the code can be cleaned up to never assume c style strings
but only LEX_STRINGS.
  • Loading branch information
cvicentiu committed Dec 10, 2016
1 parent 3e8155c commit eb4f2e0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions mysql-test/suite/roles/create_and_drop_role.result
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,19 @@ GRANT USAGE ON *.* TO 'r1'@'localhost'
DROP USER u1;
DROP ROLE r2;
DROP USER r1@localhost;
create role 'foo ';
select concat(user, '__'), is_role from mysql.user where user like 'foo%';
concat(user, '__') is_role
foo__ Y
select * from mysql.roles_mapping;
Host User Role Admin_option
localhost root foo Y
drop role foo;
select concat(user, '__'), is_role from mysql.user where user like 'foo%';
concat(user, '__') is_role
select * from mysql.roles_mapping;
Host User Role Admin_option
show grants;
Grants for root@localhost
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION
GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION
12 changes: 12 additions & 0 deletions mysql-test/suite/roles/create_and_drop_role.test
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,15 @@ SHOW GRANTS FOR r1@localhost; # Related to MDEV-7774, also caused a crash, by
DROP USER u1;
DROP ROLE r2;
DROP USER r1@localhost;

#
# MDEV-11533: Roles with trailing white spaces are not cleared correctly
#
create role 'foo ';
select concat(user, '__'), is_role from mysql.user where user like 'foo%';
select * from mysql.roles_mapping;
drop role foo;
select concat(user, '__'), is_role from mysql.user where user like 'foo%';
select * from mysql.roles_mapping;
--sorted_result
show grants;
1 change: 1 addition & 0 deletions sql/sql_yacc.yy
Original file line number Diff line number Diff line change
Expand Up @@ -15178,6 +15178,7 @@ grant_role:
CHARSET_INFO *cs= system_charset_info;
/* trim end spaces (as they'll be lost in mysql.user anyway) */
$1.length= cs->cset->lengthsp(cs, $1.str, $1.length);
$1.str[$1.length] = '\0';
if ($1.length == 0)
{
my_error(ER_INVALID_ROLE, MYF(0), "");
Expand Down

0 comments on commit eb4f2e0

Please sign in to comment.