Commit baacdf1d authored by Sergey Glukhov's avatar Sergey Glukhov

Bug#49501 Inefficient information_schema check (system collation)

added check_length optimization for I_S_NAME comparison
parent 22cff392
......@@ -1401,7 +1401,7 @@ Event_job_data::execute(THD *thd, bool drop)
#endif
if (check_access(thd, EVENT_ACL, dbname.str,
0, 0, 0, is_schema_db(dbname.str)))
0, 0, 0, is_schema_db(dbname.str, dbname.length)))
{
/*
This aspect of behavior is defined in the worklog,
......
......@@ -415,7 +415,8 @@ Events::create_event(THD *thd, Event_parse_data *parse_data,
DBUG_ASSERT(parse_data->expression || parse_data->execute_at);
if (check_access(thd, EVENT_ACL, parse_data->dbname.str, 0, 0, 0,
is_schema_db(parse_data->dbname.str)))
is_schema_db(parse_data->dbname.str,
parse_data->dbname.length)))
DBUG_RETURN(TRUE);
if (check_db_dir_existence(parse_data->dbname.str))
......@@ -526,7 +527,8 @@ Events::update_event(THD *thd, Event_parse_data *parse_data,
DBUG_RETURN(TRUE);
if (check_access(thd, EVENT_ACL, parse_data->dbname.str, 0, 0, 0,
is_schema_db(parse_data->dbname.str)))
is_schema_db(parse_data->dbname.str,
parse_data->dbname.length)))
DBUG_RETURN(TRUE);
if (new_dbname) /* It's a rename */
......@@ -548,7 +550,7 @@ Events::update_event(THD *thd, Event_parse_data *parse_data,
access it.
*/
if (check_access(thd, EVENT_ACL, new_dbname->str, 0, 0, 0,
is_schema_db(new_dbname->str)))
is_schema_db(new_dbname->str, new_dbname->length)))
DBUG_RETURN(TRUE);
/* Check that the target database exists */
......@@ -653,7 +655,7 @@ Events::drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists)
DBUG_RETURN(TRUE);
if (check_access(thd, EVENT_ACL, dbname.str, 0, 0, 0,
is_schema_db(dbname.str)))
is_schema_db(dbname.str, dbname.length)))
DBUG_RETURN(TRUE);
/*
......@@ -811,7 +813,7 @@ Events::show_create_event(THD *thd, LEX_STRING dbname, LEX_STRING name)
DBUG_RETURN(TRUE);
if (check_access(thd, EVENT_ACL, dbname.str, 0, 0, 0,
is_schema_db(dbname.str)))
is_schema_db(dbname.str, dbname.length)))
DBUG_RETURN(TRUE);
/*
......@@ -869,7 +871,8 @@ Events::fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */)
if (thd->lex->sql_command == SQLCOM_SHOW_EVENTS)
{
DBUG_ASSERT(thd->lex->select_lex.db);
if (!is_schema_db(thd->lex->select_lex.db) && // There is no events in I_S
if (!is_schema_db(thd->lex->select_lex.db, // There is no events in I_S
strlen(thd->lex->select_lex.db)) &&
check_access(thd, EVENT_ACL, thd->lex->select_lex.db, 0, 0, 0, 0))
DBUG_RETURN(1);
db= thd->lex->select_lex.db;
......
......@@ -1415,8 +1415,12 @@ bool get_schema_tables_result(JOIN *join,
enum enum_schema_table_state executed_place);
enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
#define is_schema_db(X) \
!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str, (X))
inline bool is_schema_db(const char *name, size_t len)
{
return (INFORMATION_SCHEMA_NAME.length == len &&
!my_strcasecmp(system_charset_info,
INFORMATION_SCHEMA_NAME.str, name));
}
/* sql_prepare.cc */
......
......@@ -905,7 +905,7 @@ bool load_master_data(THD* thd)
if (!rpl_filter->db_ok(db) ||
!rpl_filter->db_ok_with_wild_table(db) ||
!strcmp(db,"mysql") ||
is_schema_db(db))
is_schema_db(db, strlen(db)))
{
*cur_table_res = 0;
continue;
......
......@@ -618,7 +618,7 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info,
DBUG_ENTER("mysql_create_db");
/* do not create 'information_schema' db */
if (!my_strcasecmp(system_charset_info, db, INFORMATION_SCHEMA_NAME.str))
if (is_schema_db(db, strlen(db)))
{
my_error(ER_DB_CREATE_EXISTS, MYF(0), db);
DBUG_RETURN(-1);
......@@ -1557,8 +1557,7 @@ bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name, bool force_switch)
}
}
if (my_strcasecmp(system_charset_info, new_db_name->str,
INFORMATION_SCHEMA_NAME.str) == 0)
if (is_schema_db(new_db_name->str, new_db_name->length))
{
/* Switch the current database to INFORMATION_SCHEMA. */
......
......@@ -1305,8 +1305,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
table_list.alias= table_list.table_name= conv_name.str;
packet= arg_end + 1;
if (!my_strcasecmp(system_charset_info, table_list.db,
INFORMATION_SCHEMA_NAME.str))
if (is_schema_db(table_list.db, table_list.db_length))
{
ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, table_list.alias);
if (schema_table)
......@@ -1368,7 +1367,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
break;
}
if (check_access(thd, CREATE_ACL, db.str , 0, 1, 0,
is_schema_db(db.str)))
is_schema_db(db.str, db.length)))
break;
general_log_print(thd, command, "%.*s", db.length, db.str);
bzero(&create_info, sizeof(create_info));
......@@ -1387,7 +1386,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
my_error(ER_WRONG_DB_NAME, MYF(0), db.str ? db.str : "NULL");
break;
}
if (check_access(thd, DROP_ACL, db.str, 0, 1, 0, is_schema_db(db.str)))
if (check_access(thd, DROP_ACL, db.str, 0, 1, 0,
is_schema_db(db.str, db.length)))
break;
if (thd->locked_tables || thd->active_transaction())
{
......@@ -2852,7 +2852,7 @@ mysql_execute_command(THD *thd)
&first_table->grant.privilege, 0, 0,
test(first_table->schema_table)) ||
check_access(thd,INSERT_ACL | CREATE_ACL,select_lex->db,&priv,0,0,
is_schema_db(select_lex->db))||
is_schema_db(select_lex->db, strlen(select_lex->db)))||
check_merge_table_access(thd, first_table->db,
(TABLE_LIST *)
create_info.merge_list.first))
......@@ -3590,7 +3590,7 @@ mysql_execute_command(THD *thd)
}
#endif
if (check_access(thd,CREATE_ACL,lex->name.str, 0, 1, 0,
is_schema_db(lex->name.str)))
is_schema_db(lex->name.str, lex->name.length)))
break;
res= mysql_create_db(thd,(lower_case_table_names == 2 ? alias :
lex->name.str), &create_info, 0);
......@@ -3625,7 +3625,7 @@ mysql_execute_command(THD *thd)
}
#endif
if (check_access(thd,DROP_ACL,lex->name.str,0,1,0,
is_schema_db(lex->name.str)))
is_schema_db(lex->name.str, lex->name.length)))
break;
if (thd->locked_tables || thd->active_transaction())
{
......@@ -3659,9 +3659,12 @@ mysql_execute_command(THD *thd)
my_error(ER_WRONG_DB_NAME, MYF(0), db->str);
break;
}
if (check_access(thd, ALTER_ACL, db->str, 0, 1, 0, is_schema_db(db->str)) ||
check_access(thd, DROP_ACL, db->str, 0, 1, 0, is_schema_db(db->str)) ||
check_access(thd, CREATE_ACL, db->str, 0, 1, 0, is_schema_db(db->str)))
if (check_access(thd, ALTER_ACL, db->str, 0, 1, 0,
is_schema_db(db->str, db->length)) ||
check_access(thd, DROP_ACL, db->str, 0, 1, 0,
is_schema_db(db->str, db->length)) ||
check_access(thd, CREATE_ACL, db->str, 0, 1, 0,
is_schema_db(db->str, db->length)))
{
res= 1;
break;
......@@ -3704,7 +3707,8 @@ mysql_execute_command(THD *thd)
break;
}
#endif
if (check_access(thd, ALTER_ACL, db->str, 0, 1, 0, is_schema_db(db->str)))
if (check_access(thd, ALTER_ACL, db->str, 0, 1, 0,
is_schema_db(db->str, db->length)))
break;
if (thd->locked_tables || thd->active_transaction())
{
......@@ -3860,7 +3864,8 @@ mysql_execute_command(THD *thd)
first_table ? &first_table->grant.privilege : 0,
first_table ? 0 : 1, 0,
first_table ? (bool) first_table->schema_table :
select_lex->db ? is_schema_db(select_lex->db) : 0))
select_lex->db ?
is_schema_db(select_lex->db, strlen(select_lex->db)) : 0))
goto error;
if (thd->security_ctx->user) // If not replication
......@@ -4203,7 +4208,8 @@ mysql_execute_command(THD *thd)
}
if (check_access(thd, CREATE_PROC_ACL, lex->sphead->m_db.str, 0, 0, 0,
is_schema_db(lex->sphead->m_db.str)))
is_schema_db(lex->sphead->m_db.str,
lex->sphead->m_db.length)))
goto create_sp_error;
if (end_active_trans(thd))
......@@ -4858,7 +4864,8 @@ mysql_execute_command(THD *thd)
res= mysql_xa_recover(thd);
break;
case SQLCOM_ALTER_TABLESPACE:
if (check_access(thd, ALTER_ACL, thd->db, 0, 1, 0, thd->db ? is_schema_db(thd->db) : 0))
if (check_access(thd, ALTER_ACL, thd->db, 0, 1, 0,
thd->db ? is_schema_db(thd->db, thd->db_length) : 0))
break;
if (!(res= mysql_alter_tablespace(thd, lex->alter_tablespace_info)))
my_ok(thd);
......@@ -5297,7 +5304,7 @@ static bool check_show_access(THD *thd, TABLE_LIST *table)
if (check_access(thd, SELECT_ACL, dst_db_name,
&thd->col_access, FALSE, FALSE,
is_schema_db(dst_db_name)))
is_schema_db(dst_db_name, strlen(dst_db_name))))
return TRUE;
if (!thd->col_access && check_grant_db(thd, dst_db_name))
......@@ -6262,8 +6269,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
ptr->force_index= test(table_options & TL_OPTION_FORCE_INDEX);
ptr->ignore_leaves= test(table_options & TL_OPTION_IGNORE_LEAVES);
ptr->derived= table->sel;
if (!ptr->derived && !my_strcasecmp(system_charset_info, ptr->db,
INFORMATION_SCHEMA_NAME.str))
if (!ptr->derived && is_schema_db(ptr->db, ptr->db_length))
{
ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, ptr->table_name);
if (!schema_table ||
......
......@@ -826,8 +826,7 @@ bool mysqld_show_create_db(THD *thd, char *dbname,
DBUG_RETURN(TRUE);
}
#endif
if (!my_strcasecmp(system_charset_info, dbname,
INFORMATION_SCHEMA_NAME.str))
if (is_schema_db(dbname, strlen(dbname)))
{
dbname= INFORMATION_SCHEMA_NAME.str;
create.default_table_charset= system_charset_info;
......@@ -2780,8 +2779,8 @@ int make_db_list(THD *thd, List<LEX_STRING> *files,
*/
if (lookup_field_vals->db_value.str)
{
if (!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str,
lookup_field_vals->db_value.str))
if (is_schema_db(lookup_field_vals->db_value.str,
lookup_field_vals->db_value.length))
{
*with_i_schema= 1;
if (files->push_back(i_s_name_copy))
......@@ -5228,7 +5227,7 @@ copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table)
*/
if (thd->lex->sql_command != SQLCOM_SHOW_EVENTS &&
check_access(thd, EVENT_ACL, et.dbname.str, 0, 0, 1,
is_schema_db(et.dbname.str)))
is_schema_db(et.dbname.str, et.dbname.length)))
DBUG_RETURN(0);
/* ->field[0] is EVENT_CATALOG and is by default NULL */
......
......@@ -268,11 +268,11 @@ bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view,
table (i.e. user will not get some privileges by view creation)
*/
if ((check_access(thd, CREATE_VIEW_ACL, view->db, &view->grant.privilege,
0, 0, is_schema_db(view->db)) ||
0, 0, is_schema_db(view->db, view->db_length)) ||
check_grant(thd, CREATE_VIEW_ACL, view, 0, 1, 0)) ||
(mode != VIEW_CREATE_NEW &&
(check_access(thd, DROP_ACL, view->db, &view->grant.privilege,
0, 0, is_schema_db(view->db)) ||
0, 0, is_schema_db(view->db, view->db_length)) ||
check_grant(thd, DROP_ACL, view, 0, 1, 0))))
goto err;
......
......@@ -212,10 +212,7 @@ TABLE_CATEGORY get_table_category(const LEX_STRING *db, const LEX_STRING *name)
DBUG_ASSERT(db != NULL);
DBUG_ASSERT(name != NULL);
if ((db->length == INFORMATION_SCHEMA_NAME.length) &&
(my_strcasecmp(system_charset_info,
INFORMATION_SCHEMA_NAME.str,
db->str) == 0))
if (is_schema_db(db->str, db->length))
{
return TABLE_CATEGORY_INFORMATION;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment