Skip to content

Commit 31d83fe

Browse files
Kristofer Älvringdahlerlend
authored andcommitted
Bug#30418070 Renaming the user table should be handled gracefully
The version checks on the mysql.user table didn't take the number of available fields in the table into account and this led to unfortunate memory address exploration. RB: 23362
1 parent 94298cb commit 31d83fe

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

mysql-test/suite/auth_sec/r/atomic_rename_user.result

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,17 @@ include/assert_binlog_events.inc
7979
include/save_binlog_position.inc
8080
DROP USER userA, userB, userX, userZ;
8181
include/save_binlog_position.inc
82+
## Malformed table should be handled gracefully
83+
RENAME TABLE mysql.user TO mysql.user_bak;
84+
CREATE TABLE mysql.user(dummy INT) ENGINE=MyISAM;
85+
FLUSH PRIVILEGES;
86+
Warnings:
87+
Warning 1805 Column count of mysql.user is wrong. Expected 51, found 1. The table is probably corrupted
88+
SHOW WARNINGS;
89+
Level Code Message
90+
Warning 1805 Column count of mysql.user is wrong. Expected 51, found 1. The table is probably corrupted
91+
DROP TABLE mysql.user;
92+
RENAME TABLE mysql.user_bak TO mysql.user;
93+
FLUSH PRIVILEGES;
8294
# End : Tests for RENAME USER
8395
# -----------------------------------------------------------------------

mysql-test/suite/auth_sec/t/atomic_rename_user.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ DROP USER userA, userB, userX, userZ;
8888

8989
--source include/save_binlog_position.inc
9090

91+
--echo ## Malformed table should be handled gracefully
92+
--disable_query_log
93+
call mtr.add_suppression('.*does not support system tables.*');
94+
call mtr.add_suppression('.*Column count of mysql.user is wrong.*');
95+
--enable_query_log
96+
97+
RENAME TABLE mysql.user TO mysql.user_bak;
98+
CREATE TABLE mysql.user(dummy INT) ENGINE=MyISAM;
99+
FLUSH PRIVILEGES;
100+
SHOW WARNINGS;
101+
DROP TABLE mysql.user;
102+
RENAME TABLE mysql.user_bak TO mysql.user;
103+
FLUSH PRIVILEGES;
104+
105+
91106
--echo # End : Tests for RENAME USER
92107

93108
--echo # -----------------------------------------------------------------------

sql/auth/auth_common.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ Mem_root_base::~Mem_root_base() {
7676
}
7777

7878
bool User_table_schema_factory::is_old_user_table_schema(TABLE *table) {
79+
if (table->visible_field_count() <
80+
User_table_old_schema::MYSQL_USER_FIELD_PASSWORD_56)
81+
return false;
7982
Field *password_field =
8083
table->field[User_table_old_schema::MYSQL_USER_FIELD_PASSWORD_56];
8184
return strncmp(password_field->field_name, "Password", 8) == 0;

0 commit comments

Comments
 (0)