1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

Merge remote-tracking branch 'mysql/5.5' into 5.5

We do not accept:
1. We did not have this problem (fixed earlier and better)
 d982e717ab Bug#27510150: MYSQLDUMP FAILS FOR SPECIFIC --WHERE CLAUSES
2. We do not have such options (an DBUG_ASSERT put just in case)
 bbc2e37fe4 Bug#27759871: BACKRONYM ISSUE IS STILL IN MYSQL 5.7
3. Serg fixed it in other way in this release:
 e48d775c6f Bug#27980823: HEAP OVERFLOW VULNERABILITIES IN MYSQL CLIENT LIBRARY
This commit is contained in:
Oleksandr Byelkin
2018-07-29 13:10:29 +02:00
11 changed files with 123 additions and 47 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates.
/* Copyright (c) 2000, 2018, Oracle and/or its affiliates.
Copyright (c) 2009, 2018, MariaDB
This program is free software; you can redistribute it and/or modify
@ -4451,6 +4451,7 @@ end_index_init:
exists.
@param thd A pointer to the thread handler object.
@param table A pointer to the table list.
@see grant_reload
@ -4459,31 +4460,22 @@ end_index_init:
@retval TRUE An error has occurred.
*/
static my_bool grant_reload_procs_priv(THD *thd)
static my_bool grant_reload_procs_priv(THD *thd, TABLE_LIST *table)
{
HASH old_proc_priv_hash, old_func_priv_hash;
TABLE_LIST table;
my_bool return_val= FALSE;
DBUG_ENTER("grant_reload_procs_priv");
table.init_one_table("mysql", 5, "procs_priv",
strlen("procs_priv"), "procs_priv",
TL_READ);
table.open_type= OT_BASE_ONLY;
if (open_and_lock_tables(thd, &table, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT))
DBUG_RETURN(TRUE);
mysql_rwlock_wrlock(&LOCK_grant);
/* Save a copy of the current hash if we need to undo the grant load */
old_proc_priv_hash= proc_priv_hash;
old_func_priv_hash= func_priv_hash;
if ((return_val= grant_load_procs_priv(table.table)))
if ((return_val= grant_load_procs_priv(table->table)))
{
/* Error; Reverting to old hash */
DBUG_PRINT("error",("Reverting to old privileges"));
grant_free();
my_hash_free(&proc_priv_hash);
my_hash_free(&func_priv_hash);
proc_priv_hash= old_proc_priv_hash;
func_priv_hash= old_func_priv_hash;
}
@ -4492,9 +4484,7 @@ static my_bool grant_reload_procs_priv(THD *thd)
my_hash_free(&old_proc_priv_hash);
my_hash_free(&old_func_priv_hash);
}
mysql_rwlock_unlock(&LOCK_grant);
close_mysql_tables(thd);
DBUG_RETURN(return_val);
}
@ -4516,7 +4506,7 @@ static my_bool grant_reload_procs_priv(THD *thd)
my_bool grant_reload(THD *thd)
{
TABLE_LIST tables[2];
TABLE_LIST tables[3];
HASH old_column_priv_hash;
MEM_ROOT old_mem;
my_bool return_val= 1;
@ -4532,15 +4522,57 @@ my_bool grant_reload(THD *thd)
tables[1].init_one_table(C_STRING_WITH_LEN("mysql"),
C_STRING_WITH_LEN("columns_priv"),
"columns_priv", TL_READ);
tables[2].init_one_table(C_STRING_WITH_LEN("mysql"),
C_STRING_WITH_LEN("procs_priv"),
"procs_priv", TL_READ);
tables[0].next_local= tables[0].next_global= tables+1;
tables[0].open_type= tables[1].open_type= OT_BASE_ONLY;
tables[1].next_local= tables[1].next_global= tables+2;
tables[0].open_type= tables[1].open_type= tables[2].open_type= OT_BASE_ONLY;
/*
Reload will work in the following manner:-
proc_priv_hash structure
/ \
not initialized initialized
/ \ |
mysql.procs_priv table Server Startup |
is missing \ |
| open_and_lock_tables()
Assume we are working on /success \failure
pre 4.1 system tables. Normal Scenario. An error is thrown.
A warning is printed Reload column privilege. Retain the old hash.
and continue with Reload function and
reloading the column procedure privileges,
privileges. if available.
*/
if (!(my_hash_inited(&proc_priv_hash)))
tables[2].open_strategy= TABLE_LIST::OPEN_IF_EXISTS;
/*
To avoid deadlocks we should obtain table locks before
obtaining LOCK_grant rwlock.
*/
if (open_and_lock_tables(thd, tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT))
{
if (thd->stmt_da->is_error())
{
sql_print_error("Fatal error: Can't open and lock privilege tables: %s",
thd->stmt_da->message());
}
goto end;
}
if (tables[2].table == NULL)
{
sql_print_warning("Table 'mysql.procs_priv' does not exist. "
"Please run mysql_upgrade.");
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_NO_SUCH_TABLE,
ER(ER_NO_SUCH_TABLE), tables[2].db,
tables[2].table_name);
}
mysql_rwlock_wrlock(&LOCK_grant);
old_column_priv_hash= column_priv_hash;
@ -4552,10 +4584,18 @@ my_bool grant_reload(THD *thd)
old_mem= memex;
init_sql_alloc(&memex, ACL_ALLOC_BLOCK_SIZE, 0);
if ((return_val= grant_load(thd, tables)))
/*
tables[2].table i.e. procs_priv can be null if we are working with
pre 4.1 privilage tables
*/
if ((return_val= (grant_load(thd, tables) ||
(tables[2].table != NULL &&
grant_reload_procs_priv(thd, &tables[2])))
))
{ // Error. Revert to old hash
DBUG_PRINT("error",("Reverting to old privileges"));
grant_free(); /* purecov: deadcode */
my_hash_free(&column_priv_hash);
free_root(&memex,MYF(0));
column_priv_hash= old_column_priv_hash; /* purecov: deadcode */
memex= old_mem; /* purecov: deadcode */
}
@ -4563,22 +4603,12 @@ my_bool grant_reload(THD *thd)
{
my_hash_free(&old_column_priv_hash);
free_root(&old_mem,MYF(0));
grant_version++;
}
mysql_rwlock_unlock(&LOCK_grant);
close_mysql_tables(thd);
/*
It is OK failing to load procs_priv table because we may be
working with 4.1 privilege tables.
*/
if (grant_reload_procs_priv(thd))
return_val= 1;
mysql_rwlock_wrlock(&LOCK_grant);
grant_version++;
mysql_rwlock_unlock(&LOCK_grant);
end:
close_mysql_tables(thd);
DBUG_RETURN(return_val);
}
@ -7155,17 +7185,12 @@ bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name,
if (!(combo=(LEX_USER*) thd->alloc(sizeof(st_lex_user))))
DBUG_RETURN(TRUE);
combo->user.str= sctx->user;
combo->user.str= (char *) sctx->priv_user;
mysql_mutex_lock(&acl_cache->lock);
if ((au= find_acl_user(combo->host.str=(char*)sctx->host_or_ip,combo->user.str,FALSE)))
goto found_acl;
if ((au= find_acl_user(combo->host.str=(char*)sctx->host, combo->user.str,FALSE)))
goto found_acl;
if ((au= find_acl_user(combo->host.str=(char*)sctx->ip, combo->user.str,FALSE)))
goto found_acl;
if((au= find_acl_user(combo->host.str=(char*)"%", combo->user.str, FALSE)))
if ((au= find_acl_user(combo->host.str= (char *) sctx->priv_host,
combo->user.str, FALSE)))
goto found_acl;
mysql_mutex_unlock(&acl_cache->lock);