Skip to content

Commit

Permalink
MDEV-30826 Invalid data on mysql.host segfaults the server after an u…
Browse files Browse the repository at this point in the history
…pgrade to 10.4

convert empty host.db to "%", just as it's done for host.hostname
(in update_hostname())
  • Loading branch information
vuvova committed Mar 10, 2023
1 parent 2ac8328 commit 8145b30
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
9 changes: 9 additions & 0 deletions mysql-test/main/grant5.result
Expand Up @@ -453,4 +453,13 @@ insert mysql.host values (1);
flush privileges;
ERROR HY000: Fatal error: mysql.host table is damaged or in unsupported 3.20 format
drop table mysql.host;
#
# MDEV-30826 Invalid data on mysql.host segfaults the server after an upgrade to 10.4
#
create table mysql.host (host char(60) binary default '' not null, db char(64) binary default '' not null, select_priv enum('n','y') collate utf8_general_ci default 'n' not null, insert_priv enum('n','y') collate utf8_general_ci default 'n' not null, update_priv enum('n','y') collate utf8_general_ci default 'n' not null, delete_priv enum('n','y') collate utf8_general_ci default 'n' not null, create_priv enum('n','y') collate utf8_general_ci default 'n' not null, drop_priv enum('n','y') collate utf8_general_ci default 'n' not null, grant_priv enum('n','y') collate utf8_general_ci default 'n' not null, references_priv enum('n','y') collate utf8_general_ci default 'n' not null, index_priv enum('n','y') collate utf8_general_ci default 'n' not null, alter_priv enum('n','y') collate utf8_general_ci default 'n' not null, create_tmp_table_priv enum('n','y') collate utf8_general_ci default 'n' not null, lock_tables_priv enum('n','y') collate utf8_general_ci default 'n' not null, create_view_priv enum('n','y') collate utf8_general_ci default 'n' not null, show_view_priv enum('n','y') collate utf8_general_ci default 'n' not null, create_routine_priv enum('n','y') collate utf8_general_ci default 'n' not null, alter_routine_priv enum('n','y') collate utf8_general_ci default 'n' not null, execute_priv enum('n','y') collate utf8_general_ci default 'n' not null, trigger_priv enum('n','y') collate utf8_general_ci default 'n' not null, primary key /*host*/ (host,db)) engine=myisam character set utf8 collate utf8_bin comment='host privileges; merged with database privileges';
insert mysql.host values('10.5.0.0/255.255.0.0','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N');
flush privileges;
drop table mysql.host;
#
# End of 10.4 tests
#
12 changes: 12 additions & 0 deletions mysql-test/main/grant5.test
Expand Up @@ -408,4 +408,16 @@ insert mysql.host values (1);
flush privileges;
drop table mysql.host;

--echo #
--echo # MDEV-30826 Invalid data on mysql.host segfaults the server after an upgrade to 10.4
--echo #

# from mysql_system_tables.sql in 10.3:
create table mysql.host (host char(60) binary default '' not null, db char(64) binary default '' not null, select_priv enum('n','y') collate utf8_general_ci default 'n' not null, insert_priv enum('n','y') collate utf8_general_ci default 'n' not null, update_priv enum('n','y') collate utf8_general_ci default 'n' not null, delete_priv enum('n','y') collate utf8_general_ci default 'n' not null, create_priv enum('n','y') collate utf8_general_ci default 'n' not null, drop_priv enum('n','y') collate utf8_general_ci default 'n' not null, grant_priv enum('n','y') collate utf8_general_ci default 'n' not null, references_priv enum('n','y') collate utf8_general_ci default 'n' not null, index_priv enum('n','y') collate utf8_general_ci default 'n' not null, alter_priv enum('n','y') collate utf8_general_ci default 'n' not null, create_tmp_table_priv enum('n','y') collate utf8_general_ci default 'n' not null, lock_tables_priv enum('n','y') collate utf8_general_ci default 'n' not null, create_view_priv enum('n','y') collate utf8_general_ci default 'n' not null, show_view_priv enum('n','y') collate utf8_general_ci default 'n' not null, create_routine_priv enum('n','y') collate utf8_general_ci default 'n' not null, alter_routine_priv enum('n','y') collate utf8_general_ci default 'n' not null, execute_priv enum('n','y') collate utf8_general_ci default 'n' not null, trigger_priv enum('n','y') collate utf8_general_ci default 'n' not null, primary key /*host*/ (host,db)) engine=myisam character set utf8 collate utf8_bin comment='host privileges; merged with database privileges';
insert mysql.host values('10.5.0.0/255.255.0.0','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N');
flush privileges;
drop table mysql.host;

--echo #
--echo # End of 10.4 tests
--echo #
7 changes: 4 additions & 3 deletions sql/sql_acl.cc
Expand Up @@ -2437,6 +2437,8 @@ static bool acl_load(THD *thd, const Grant_tables& tables)
"possible to remove this privilege using REVOKE.",
host.host.hostname, host.db);
}
else if (!host.db)
host.db= const_cast<char*>(host_not_specified.str);
host.access= host_table.get_access();
host.access= fix_rights_for_db(host.access);
host.sort= get_magic_sort("hd", host.host.hostname, host.db);
Expand All @@ -2445,8 +2447,7 @@ static bool acl_load(THD *thd, const Grant_tables& tables)
{
sql_print_warning("'host' entry '%s|%s' "
"ignored in --skip-name-resolve mode.",
safe_str(host.host.hostname),
safe_str(host.db));
host.host.hostname, host.db);
continue;
}
#ifndef TO_BE_REMOVED
Expand Down Expand Up @@ -3533,7 +3534,7 @@ ulong acl_get(const char *host, const char *ip,
ACL_HOST *acl_host=dynamic_element(&acl_hosts,i,ACL_HOST*);
if (compare_hostname(&acl_host->host,host,ip))
{
if (!acl_host->db || !wild_compare(db,acl_host->db,db_is_pattern))
if (!wild_compare(db, acl_host->db, db_is_pattern))
{
host_access=acl_host->access; // Fully specified. Take it
break;
Expand Down

0 comments on commit 8145b30

Please sign in to comment.