diff options
author | Vicențiu Ciorbaru <vicentiu@mariadb.org> | 2016-12-10 22:19:09 +0200 |
---|---|---|
committer | Vicențiu Ciorbaru <vicentiu@mariadb.org> | 2016-12-10 22:23:25 +0200 |
commit | eb4f2e063c341d9f3644339c68cb01679e782001 (patch) | |
tree | c25b7269100f45ffdf2520c3d1d61b3272fcb890 | |
parent | 3e8155c637096da8fd019c42b78746be2bf89944 (diff) | |
download | mariadb-git-eb4f2e063c341d9f3644339c68cb01679e782001.tar.gz |
MDEV-11533: Roles with trailing white spaces are not cleared correctly
Role names with trailing whitespaces are truncated in length as of
956e92d90873532fee95581c702f7b76643969ea 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.
-rw-r--r-- | mysql-test/suite/roles/create_and_drop_role.result | 16 | ||||
-rw-r--r-- | mysql-test/suite/roles/create_and_drop_role.test | 12 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 1 |
3 files changed, 29 insertions, 0 deletions
diff --git a/mysql-test/suite/roles/create_and_drop_role.result b/mysql-test/suite/roles/create_and_drop_role.result index d565b888c5f..13631f935bf 100644 --- a/mysql-test/suite/roles/create_and_drop_role.result +++ b/mysql-test/suite/roles/create_and_drop_role.result @@ -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 diff --git a/mysql-test/suite/roles/create_and_drop_role.test b/mysql-test/suite/roles/create_and_drop_role.test index 71d6de7053f..b6e5bd2b297 100644 --- a/mysql-test/suite/roles/create_and_drop_role.test +++ b/mysql-test/suite/roles/create_and_drop_role.test @@ -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; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index c1cd2a94130..c9fd000141a 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -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), ""); |