Skip to content

Commit f73417b

Browse files
Kristofer Älvringdahlerlend
authored andcommitted
Bug#29873343 WHEN WRITING EMPTY PRIVILEGES INTO GLOBAL_GRANTS TABLE
This patch improve stability of the global_grants table when unexpected values has been inserted in the system table. RB: 23168
1 parent ceb618a commit f73417b

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

mysql-test/r/grant_dynamic.result

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,3 +1131,22 @@ binlog.000001 # Query # # use `test`; GRANT GRANT OPTION ON *.* TO 'u1'@'%' WITH
11311131
DROP USER u1;
11321132
RESET MASTER;
11331133
RESET SLAVE ALL;
1134+
#
1135+
# WRITING EMPTY PRIVILEGES INTO GLOBAL_GRANTS TABLE
1136+
#
1137+
INSERT INTO mysql.global_grants (user, host, priv) values ('', '%', ' ');
1138+
FLUSH PRIVILEGES;
1139+
DELETE FROM mysql.global_grants WHERE user = '' AND host = '%' AND priv = ' ';
1140+
INSERT INTO mysql.global_grants (user, host, priv) values ('', '', '');
1141+
FLUSH PRIVILEGES;
1142+
DELETE FROM mysql.global_grants WHERE user = '' AND host = '' AND priv = '';
1143+
INSERT INTO mysql.global_grants (user, host, priv) values (' ', '', '');
1144+
FLUSH PRIVILEGES;
1145+
DELETE FROM mysql.global_grants WHERE user = '' AND host = ' ' AND priv = '';
1146+
INSERT INTO mysql.global_grants (user, host, priv) values (' ', ' ', '');
1147+
FLUSH PRIVILEGES;
1148+
DELETE FROM mysql.global_grants WHERE user = ' ' AND host = ' ' AND priv = '';
1149+
INSERT INTO mysql.global_grants (user, host, priv) values ('', '', ' ');
1150+
FLUSH PRIVILEGES;
1151+
DELETE FROM mysql.global_grants WHERE user = '' AND host = '' AND priv = ' ';
1152+
FLUSH PRIVILEGES;

mysql-test/t/grant_dynamic.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,3 +614,24 @@ GRANT GRANT OPTION ON *.* TO u1;
614614
DROP USER u1;
615615
RESET MASTER;
616616
RESET SLAVE ALL;
617+
618+
--echo #
619+
--echo # WRITING EMPTY PRIVILEGES INTO GLOBAL_GRANTS TABLE
620+
--echo #
621+
INSERT INTO mysql.global_grants (user, host, priv) values ('', '%', ' ');
622+
FLUSH PRIVILEGES;
623+
DELETE FROM mysql.global_grants WHERE user = '' AND host = '%' AND priv = ' ';
624+
INSERT INTO mysql.global_grants (user, host, priv) values ('', '', '');
625+
FLUSH PRIVILEGES;
626+
DELETE FROM mysql.global_grants WHERE user = '' AND host = '' AND priv = '';
627+
INSERT INTO mysql.global_grants (user, host, priv) values (' ', '', '');
628+
FLUSH PRIVILEGES;
629+
DELETE FROM mysql.global_grants WHERE user = '' AND host = ' ' AND priv = '';
630+
INSERT INTO mysql.global_grants (user, host, priv) values (' ', ' ', '');
631+
FLUSH PRIVILEGES;
632+
DELETE FROM mysql.global_grants WHERE user = ' ' AND host = ' ' AND priv = '';
633+
INSERT INTO mysql.global_grants (user, host, priv) values ('', '', ' ');
634+
FLUSH PRIVILEGES;
635+
DELETE FROM mysql.global_grants WHERE user = '' AND host = '' AND priv = ' ';
636+
FLUSH PRIVILEGES;
637+

sql/auth/dynamic_privilege_table.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ bool populate_dynamic_privilege_caches(THD *thd, TABLE_LIST *tablelst) {
107107
int read_rec_errcode;
108108
MEM_ROOT tmp_mem;
109109
char percentile_character[2] = {'%', '\0'};
110+
char empty_str = '\0';
110111
/*
111112
We need the the dynamic privilege register in order to register any unknown
112113
privilege identifiers.
@@ -123,14 +124,14 @@ bool populate_dynamic_privilege_caches(THD *thd, TABLE_LIST *tablelst) {
123124
char *host =
124125
get_field(&tmp_mem, table->field[MYSQL_DYNAMIC_PRIV_FIELD_HOST]);
125126
if (host == 0) host = &percentile_character[0];
126-
const char *user =
127+
char *user =
127128
get_field(&tmp_mem, table->field[MYSQL_DYNAMIC_PRIV_FIELD_USER]);
128-
if (user == nullptr) user = "\0";
129+
if (user == nullptr) user = &empty_str;
129130
char *priv =
130131
get_field(&tmp_mem, table->field[MYSQL_DYNAMIC_PRIV_FIELD_PRIV]);
131132
char *with_grant_option = get_field(
132133
&tmp_mem, table->field[MYSQL_DYNAMIC_PRIV_FIELD_WITH_GRANT_OPTION]);
133-
134+
if (priv == nullptr) priv = &empty_str;
134135
my_caseup_str(system_charset_info, priv);
135136
LEX_CSTRING str_priv = {priv, strlen(priv)};
136137
LEX_CSTRING str_user = {user, strlen(user)};

0 commit comments

Comments
 (0)