Skip to content

Commit 0d63fd5

Browse files
Bug#20561087 : REPLACE_USER_TABLE() DOES NOT CHECK ERROR WHEN READING FROM MYSQL.USER
Problem : Code responsible for reading/writing from/to acl tables assume that storage engine is always MYISAM. Hence, some errors reported by different storage engines (e.g. ndb) are not processed correctly. Solution : Handle errors thrown by storage engine and bail out if error is not acceptable. This change also signals transaction rollback to storage engine in case of an unexpected error by storage engine. Reviewed-By: Georgi Kodinov <[email protected]> Reviewed-By: Dmitry Lenev <[email protected]> Reviewed-By: Magnus Blåudd <[email protected]>
1 parent ccffca6 commit 0d63fd5

12 files changed

+1321
-445
lines changed

libmysqld/lib_sql.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,7 @@ int init_embedded_server(int argc, char **argv, char **groups)
617617

618618
acl_error= 0;
619619
#ifndef NO_EMBEDDED_ACCESS_CHECKS
620-
if (!(acl_error= acl_init(opt_noacl)) &&
621-
!opt_noacl)
622-
(void) grant_init();
620+
acl_error= acl_init(opt_noacl) || grant_init(opt_noacl);
623621
#endif
624622
if (acl_error || my_tz_init((THD *)0, default_tz_name, opt_bootstrap))
625623
{
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
call mtr.add_suppression("Did not write failed");
2+
SET @old_debug= @@SESSION.debug;
3+
SET DEBUG='+d, se_error_replace_user_table_read';
4+
CREATE USER 'foo'@'localhost' IDENTIFIED BY 'abcd';
5+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
6+
SET DEBUG='-d, se_error_replace_user_table_read';
7+
SET DEBUG='+d, se_error_replace_user_table_add';
8+
CREATE USER 'foo'@'localhost' IDENTIFIED BY 'abcd';
9+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
10+
SET DEBUG='-d, se_error_replace_user_table_add';
11+
CREATE USER 'foo'@'localhost' IDENTIFIED BY 'abcd';
12+
SET DEBUG='+d, se_error_replace_user_table_update';
13+
ALTER USER 'foo'@'localhost' PASSWORD EXPIRE;
14+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
15+
SET DEBUG='-d, se_error_replace_user_table_update';
16+
SET DEBUG='+d, se_error_replace_db_table_read';
17+
GRANT SELECT ON mysql.* TO 'foo'@'localhost';
18+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
19+
SET DEBUG='-d, se_error_replace_db_table_read';
20+
SET DEBUG='+d, se_error_replace_db_table_add';
21+
GRANT SELECT ON mysql.* TO 'foo'@'localhost';
22+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
23+
SET DEBUG='-d, se_error_replace_db_table_add';
24+
GRANT SELECT ON mysql.* TO 'foo'@'localhost';
25+
SET DEBUG='+d, se_error_replace_db_table_update';
26+
GRANT UPDATE ON mysql.* TO 'foo'@'localhost';
27+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
28+
SET DEBUG='-d, se_error_replace_db_table_update';
29+
SET DEBUG='+d, se_error_replace_db_table_delete';
30+
REVOKE SELECT, UPDATE ON mysql.* FROM 'foo'@'localhost';
31+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
32+
SET DEBUG='-d, se_error_replace_db_table_delete';
33+
REVOKE SELECT, UPDATE ON mysql.* FROM 'foo'@'localhost';
34+
CREATE USER 'bar'@'localhost';
35+
SET DEBUG='+d, se_error_replace_proxies_priv_table_read';
36+
GRANT PROXY ON 'foo'@'localhost' TO 'bar'@'localhost';
37+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
38+
SET DEBUG='-d, se_error_replace_proxies_priv_table_read';
39+
SET DEBUG='+d, se_error_replace_proxies_priv_table_add';
40+
GRANT PROXY ON 'foo'@'localhost' TO 'bar'@'localhost';
41+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
42+
SET DEBUG='-d, se_error_replace_proxies_priv_table_add';
43+
GRANT PROXY ON 'foo'@'localhost' TO 'bar'@'localhost';
44+
SET DEBUG='+d, se_error_replace_proxies_priv_table_update';
45+
GRANT PROXY ON 'foo'@'localhost' TO 'bar'@'localhost';
46+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
47+
SET DEBUG='-d, se_error_replace_proxies_priv_table_update';
48+
SET DEBUG='+d, se_error_replace_proxies_priv_table_delete';
49+
REVOKE PROXY ON 'foo'@'localhost' FROM 'bar'@'localhost';
50+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
51+
SET DEBUG='-d, se_error_replace_proxies_priv_table_delete';
52+
CREATE TABLE test.t1(c1 int, c2 int);
53+
SET DEBUG='+d, se_error_replace_column_table_read';
54+
GRANT SELECT(c1) ON test.t1 TO 'foo'@'localhost';
55+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
56+
SET DEBUG='-d, se_error_replace_column_table_read';
57+
SET DEBUG='+d, se_error_replace_column_table_add';
58+
GRANT SELECT(c1) ON test.t1 TO 'foo'@'localhost';
59+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
60+
SET DEBUG='-d, se_error_replace_column_table_add';
61+
GRANT SELECT(c1) ON test.t1 TO 'foo'@'localhost';
62+
SET DEBUG='+d, se_error_replace_column_table_update';
63+
GRANT UPDATE(c1) ON test.t1 TO 'foo'@'localhost';
64+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
65+
SET DEBUG='-d, se_error_replace_column_table_update';
66+
REVOKE UPDATE ON test.t1 FROM 'foo'@'localhost';
67+
SET DEBUG='+d, se_error_replace_column_table_delete';
68+
REVOKE SELECT(c1) ON test.t1 FROM 'foo'@'localhost';
69+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
70+
SET DEBUG='-d, se_error_replace_column_table_delete';
71+
GRANT SELECT(c1), UPDATE(c1) ON test.t1 TO 'foo'@'localhost';
72+
FLUSH PRIVILEGES;
73+
SET DEBUG='+d, se_error_replace_column_table_revoke_read';
74+
REVOKE SELECT ON test.t1 FROM 'foo'@'localhost';
75+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
76+
SET DEBUG='-d, se_error_replace_column_table_revoke_read';
77+
GRANT SELECT(c1) ON test.t1 TO 'foo'@'localhost';
78+
FLUSH PRIVILEGES;
79+
SET DEBUG='+d, se_error_replace_column_table_revoke_update';
80+
REVOKE UPDATE ON test.t1 FROM 'foo'@'localhost';
81+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
82+
SET DEBUG='-d, se_error_replace_column_table_revoke_update';
83+
REVOKE UPDATE ON test.t1 FROM 'foo'@'localhost';
84+
SET DEBUG='+d, se_error_replace_column_table_revoke_delete';
85+
REVOKE SELECT ON test.t1 FROM 'foo'@'localhost';
86+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
87+
SET DEBUG='-d, se_error_replace_column_table_revoke_delete';
88+
GRANT SELECT(c1) ON test.t1 TO 'foo'@'localhost';
89+
SET DEBUG='+d, se_error_replace_column_table_revoke_read_next';
90+
REVOKE SELECT ON test.t1 FROM 'foo'@'localhost';
91+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
92+
SET DEBUG='-d, se_error_replace_column_table_revoke_read_next';
93+
DROP TABLE test.t1;
94+
CREATE TABLE test.t2(c1 int, c2 int);
95+
SET DEBUG='+d, se_error_replace_table_table_read';
96+
GRANT SELECT ON test.t2 TO 'foo'@'localhost';
97+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
98+
SET DEBUG='-d, se_error_replace_table_table_read';
99+
SET DEBUG='+d, se_error_replace_table_table_add';
100+
GRANT SELECT ON test.t2 TO 'foo'@'localhost';
101+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
102+
SET DEBUG='-d, se_error_replace_table_table_add';
103+
GRANT SELECT ON test.t2 TO 'foo'@'localhost';
104+
SET DEBUG='+d, se_error_replace_table_table_update';
105+
GRANT UPDATE ON test.t2 TO 'foo'@'localhost';
106+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
107+
SET DEBUG='-d, se_error_replace_table_table_update';
108+
DROP TABLE test.t2;
109+
CREATE PROCEDURE test.p1()
110+
SELECT 1;
111+
SET DEBUG='+d, se_error_replace_routine_table_read';
112+
GRANT EXECUTE ON PROCEDURE test.p1 TO 'foo'@'localhost';
113+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
114+
SET DEBUG='-d, se_error_replace_routine_table_read';
115+
SET DEBUG='+d, se_error_replace_routine_table_add';
116+
GRANT EXECUTE ON PROCEDURE test.p1 TO 'foo'@'localhost';
117+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
118+
SET DEBUG='-d, se_error_replace_routine_table_add';
119+
GRANT EXECUTE ON PROCEDURE test.p1 TO 'foo'@'localhost';
120+
SET DEBUG='+d, se_error_replace_routine_table_update';
121+
GRANT ALTER ROUTINE ON PROCEDURE test.p1 TO 'foo'@'localhost';
122+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
123+
SET DEBUG='-d, se_error_replace_routine_table_update';
124+
SET DEBUG='+d, se_error_replace_routine_table_delete';
125+
REVOKE ALL PRIVILEGES ON PROCEDURE test.p1 FROM 'foo'@'localhost';
126+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
127+
SET DEBUG='-d, se_error_replace_routine_table_delete';
128+
SET DEBUG='+d, se_error_modify_grant_table_update';
129+
RENAME USER 'foo'@'localhost' TO 'foo_new'@'localhost';
130+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
131+
SET DEBUG='-d, se_error_modify_grant_table_update';
132+
SET DEBUG='+d, se_error_handle_grant_table_read';
133+
RENAME USER 'foo'@'localhost' TO 'foo_new'@'localhost';
134+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
135+
SET DEBUG='-d, se_error_handle_grant_table_read';
136+
SET DEBUG='+d, se_error_handle_grant_table_rnd_read';
137+
RENAME USER 'foo'@'localhost' TO 'foo_new'@'localhost';
138+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
139+
SET DEBUG='-d, se_error_handle_grant_table_rnd_read';
140+
SET DEBUG='+d, se_error_modify_grant_table_delete';
141+
DROP USER 'foo'@'localhost';
142+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
143+
SET DEBUG='-d, se_error_modify_grant_table_delete';
144+
DROP PROCEDURE test.p1;
145+
DROP USER 'foo'@'localhost';
146+
CREATE TABLE t1(a INT);
147+
CREATE USER 'foo'@'localhost';
148+
GRANT UPDATE (a) ON t1 TO 'foo'@'localhost';
149+
SET DEBUG='+d, se_error_grant_table_init_read';
150+
FLUSH PRIVILEGES;
151+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
152+
SET DEBUG='-d, se_error_grant_table_init_read';
153+
SET DEBUG='+d, se_error_grant_table_init_read_next';
154+
FLUSH PRIVILEGES;
155+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
156+
SET DEBUG='-d, se_error_grant_table_init_read_next';
157+
CREATE PROCEDURE p() SET @x = 1;
158+
GRANT EXECUTE ON PROCEDURE p TO 'foo'@'localhost';
159+
SET DEBUG='+d, se_error_grant_load_read';
160+
FLUSH PRIVILEGES;
161+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
162+
SET DEBUG='-d, se_error_grant_load_read';
163+
SET DEBUG='+d, se_error_grant_load_read_next';
164+
FLUSH PRIVILEGES;
165+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
166+
SET DEBUG='-d, se_error_grant_load_read_next';
167+
SET DEBUG='+d, se_error_grant_load_procs_read';
168+
FLUSH PRIVILEGES;
169+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
170+
SET DEBUG='-d, se_error_grant_load_procs_read';
171+
SET DEBUG='+d, se_error_grant_load_procs_read_next';
172+
FLUSH PRIVILEGES;
173+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
174+
SET DEBUG='-d, se_error_grant_load_procs_read_next';
175+
DROP USER 'foo'@'localhost';
176+
DROP TABLE t1;
177+
DROP PROCEDURE p;
178+
SET DEBUG= @old_global_debug;
179+
DROP USER 'bar'@'localhost';

0 commit comments

Comments
 (0)