Commit 71e84df0 authored by unknown's avatar unknown

After merge fixes.


sql/event_timed.cc:
  After merge fixes: dbname can never be NULL.
sql/events.cc:
  After merge fixes: use a new signature of sp_use_new_db
sql/sp_head.cc:
  After merge fixes: replace assert with an if for events code to work.
sql/sql_parse.cc:
  After merge fixes: put back free_items, it's used in partitioning.
  Whether it is not a bug is to be investigated.
  Remove check_db_used, as planned.
parent df9b4754
...@@ -143,24 +143,13 @@ Event_timed::init_name(THD *thd, sp_name *spn) ...@@ -143,24 +143,13 @@ Event_timed::init_name(THD *thd, sp_name *spn)
MEM_ROOT *root= thd->mem_root; MEM_ROOT *root= thd->mem_root;
/* We have to copy strings to get them into the right memroot */ /* We have to copy strings to get them into the right memroot */
if (spn) dbname.length= spn->m_db.length;
{ dbname.str= strmake_root(root, spn->m_db.str, spn->m_db.length);
dbname.length= spn->m_db.length; name.length= spn->m_name.length;
if (spn->m_db.length == 0) name.str= strmake_root(root, spn->m_name.str, spn->m_name.length);
dbname.str= NULL;
else
dbname.str= strmake_root(root, spn->m_db.str, spn->m_db.length);
name.length= spn->m_name.length;
name.str= strmake_root(root, spn->m_name.str, spn->m_name.length);
if (spn->m_qname.length == 0) if (spn->m_qname.length == 0)
spn->init_qname(thd); spn->init_qname(thd);
}
else if (thd->db)
{
dbname.length= thd->db_length;
dbname.str= strmake_root(root, thd->db, dbname.length);
}
DBUG_PRINT("dbname", ("len=%d db=%s",dbname.length, dbname.str)); DBUG_PRINT("dbname", ("len=%d db=%s",dbname.length, dbname.str));
DBUG_PRINT("name", ("len=%d name=%s",name.length, name.str)); DBUG_PRINT("name", ("len=%d name=%s",name.length, name.str));
......
...@@ -598,8 +598,9 @@ db_create_event(THD *thd, Event_timed *et, my_bool create_if_not, ...@@ -598,8 +598,9 @@ db_create_event(THD *thd, Event_timed *et, my_bool create_if_not,
int ret= 0; int ret= 0;
CHARSET_INFO *scs= system_charset_info; CHARSET_INFO *scs= system_charset_info;
TABLE *table; TABLE *table;
char olddb[128]; char old_db_buf[NAME_LEN+1];
bool dbchanged= false; LEX_STRING old_db= { old_db_buf, sizeof(old_db_buf) };
bool dbchanged;
DBUG_ENTER("db_create_event"); DBUG_ENTER("db_create_event");
DBUG_PRINT("enter", ("name: %.*s", et->name.length, et->name.str)); DBUG_PRINT("enter", ("name: %.*s", et->name.length, et->name.str));
...@@ -626,8 +627,7 @@ db_create_event(THD *thd, Event_timed *et, my_bool create_if_not, ...@@ -626,8 +627,7 @@ db_create_event(THD *thd, Event_timed *et, my_bool create_if_not,
} }
DBUG_PRINT("info", ("non-existant, go forward")); DBUG_PRINT("info", ("non-existant, go forward"));
if ((ret= sp_use_new_db(thd, et->dbname.str,olddb, sizeof(olddb),0, if ((ret= sp_use_new_db(thd, et->dbname, &old_db, 0, &dbchanged)))
&dbchanged)))
{ {
my_error(ER_BAD_DB_ERROR, MYF(0)); my_error(ER_BAD_DB_ERROR, MYF(0));
goto err; goto err;
...@@ -691,14 +691,14 @@ db_create_event(THD *thd, Event_timed *et, my_bool create_if_not, ...@@ -691,14 +691,14 @@ db_create_event(THD *thd, Event_timed *et, my_bool create_if_not,
*rows_affected= 1; *rows_affected= 1;
ok: ok:
if (dbchanged) if (dbchanged)
(void) mysql_change_db(thd, olddb, 1); (void) mysql_change_db(thd, old_db.str, 1);
if (table) if (table)
close_thread_tables(thd); close_thread_tables(thd);
DBUG_RETURN(EVEX_OK); DBUG_RETURN(EVEX_OK);
err: err:
if (dbchanged) if (dbchanged)
(void) mysql_change_db(thd, olddb, 1); (void) mysql_change_db(thd, old_db.str, 1);
if (table) if (table)
close_thread_tables(thd); close_thread_tables(thd);
DBUG_RETURN(EVEX_GENERAL_ERROR); DBUG_RETURN(EVEX_GENERAL_ERROR);
......
...@@ -495,20 +495,32 @@ sp_head::init_strings(THD *thd, LEX *lex, sp_name *name) ...@@ -495,20 +495,32 @@ sp_head::init_strings(THD *thd, LEX *lex, sp_name *name)
/* During parsing, we must use thd->mem_root */ /* During parsing, we must use thd->mem_root */
MEM_ROOT *root= thd->mem_root; MEM_ROOT *root= thd->mem_root;
DBUG_ASSERT(name); if (name)
/* Must be initialized in the parser */ {
DBUG_ASSERT(name->m_db.str && name->m_db.length); /* Must be initialized in the parser */
DBUG_ASSERT(name->m_db.str && name->m_db.length);
/* We have to copy strings to get them into the right memroot */
m_db.length= name->m_db.length; /* We have to copy strings to get them into the right memroot */
m_db.str= strmake_root(root, name->m_db.str, name->m_db.length); m_db.length= name->m_db.length;
m_name.length= name->m_name.length; m_db.str= strmake_root(root, name->m_db.str, name->m_db.length);
m_name.str= strmake_root(root, name->m_name.str, name->m_name.length); m_name.length= name->m_name.length;
m_name.str= strmake_root(root, name->m_name.str, name->m_name.length);
if (name->m_qname.length == 0)
name->init_qname(thd); if (name->m_qname.length == 0)
m_qname.length= name->m_qname.length; name->init_qname(thd);
m_qname.str= strmake_root(root, name->m_qname.str, m_qname.length); m_qname.length= name->m_qname.length;
m_qname.str= strmake_root(root, name->m_qname.str, m_qname.length);
}
else
{
/*
FIXME: the only use case when name is NULL is events, and it should
be rewritten soon. Remove the else part and replace 'if' with
an assert when this is done.
*/
LEX_STRING str_reset= { NULL, 0 };
m_db= m_name= m_qname= str_reset;
}
if (m_param_begin && m_param_end) if (m_param_begin && m_param_end)
{ {
......
...@@ -66,7 +66,6 @@ static void time_out_user_resource_limits(THD *thd, USER_CONN *uc); ...@@ -66,7 +66,6 @@ static void time_out_user_resource_limits(THD *thd, USER_CONN *uc);
static int check_for_max_user_connections(THD *thd, USER_CONN *uc); static int check_for_max_user_connections(THD *thd, USER_CONN *uc);
#endif #endif
static void decrease_user_connections(USER_CONN *uc); static void decrease_user_connections(USER_CONN *uc);
static bool check_db_used(THD *thd,TABLE_LIST *tables);
static bool check_multi_update_lock(THD *thd); static bool check_multi_update_lock(THD *thd);
static void remove_escape(char *name); static void remove_escape(char *name);
static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables); static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables);
...@@ -1362,7 +1361,21 @@ pthread_handler_t handle_bootstrap(void *arg) ...@@ -1362,7 +1361,21 @@ pthread_handler_t handle_bootstrap(void *arg)
} }
/* This works because items are allocated with sql_alloc() */ /* This works because items are allocated with sql_alloc() */
void free_items(Item *item)
{
Item *next;
DBUG_ENTER("free_items");
for (; item ; item=next)
{
next=item->next;
item->delete_self();
}
DBUG_VOID_RETURN;
}
/* This works because items are allocated with sql_alloc() */
void cleanup_items(Item *item) void cleanup_items(Item *item)
{ {
...@@ -2719,8 +2732,7 @@ mysql_execute_command(THD *thd) ...@@ -2719,8 +2732,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_BACKUP_TABLE: case SQLCOM_BACKUP_TABLE:
{ {
DBUG_ASSERT(first_table == all_tables && first_table != 0); DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) || if (check_table_access(thd, SELECT_ACL, all_tables, 0) ||
check_table_access(thd, SELECT_ACL, all_tables, 0) ||
check_global_access(thd, FILE_ACL)) check_global_access(thd, FILE_ACL))
goto error; /* purecov: inspected */ goto error; /* purecov: inspected */
thd->enable_slow_log= opt_log_slow_admin_statements; thd->enable_slow_log= opt_log_slow_admin_statements;
...@@ -2732,8 +2744,7 @@ mysql_execute_command(THD *thd) ...@@ -2732,8 +2744,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_RESTORE_TABLE: case SQLCOM_RESTORE_TABLE:
{ {
DBUG_ASSERT(first_table == all_tables && first_table != 0); DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) || if (check_table_access(thd, INSERT_ACL, all_tables, 0) ||
check_table_access(thd, INSERT_ACL, all_tables, 0) ||
check_global_access(thd, FILE_ACL)) check_global_access(thd, FILE_ACL))
goto error; /* purecov: inspected */ goto error; /* purecov: inspected */
thd->enable_slow_log= opt_log_slow_admin_statements; thd->enable_slow_log= opt_log_slow_admin_statements;
...@@ -2745,8 +2756,7 @@ mysql_execute_command(THD *thd) ...@@ -2745,8 +2756,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_ASSIGN_TO_KEYCACHE: case SQLCOM_ASSIGN_TO_KEYCACHE:
{ {
DBUG_ASSERT(first_table == all_tables && first_table != 0); DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) || if (check_access(thd, INDEX_ACL, first_table->db,
check_access(thd, INDEX_ACL, first_table->db,
&first_table->grant.privilege, 0, 0, &first_table->grant.privilege, 0, 0,
test(first_table->schema_table))) test(first_table->schema_table)))
goto error; goto error;
...@@ -2756,8 +2766,7 @@ mysql_execute_command(THD *thd) ...@@ -2756,8 +2766,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_PRELOAD_KEYS: case SQLCOM_PRELOAD_KEYS:
{ {
DBUG_ASSERT(first_table == all_tables && first_table != 0); DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) || if (check_access(thd, INDEX_ACL, first_table->db,
check_access(thd, INDEX_ACL, first_table->db,
&first_table->grant.privilege, 0, 0, &first_table->grant.privilege, 0, 0,
test(first_table->schema_table))) test(first_table->schema_table)))
goto error; goto error;
...@@ -3131,8 +3140,6 @@ mysql_execute_command(THD *thd) ...@@ -3131,8 +3140,6 @@ mysql_execute_command(THD *thd)
{ {
DBUG_ASSERT(first_table == all_tables && first_table != 0); DBUG_ASSERT(first_table == all_tables && first_table != 0);
TABLE_LIST *table; TABLE_LIST *table;
if (check_db_used(thd, all_tables))
goto error;
for (table= first_table; table; table= table->next_local->next_local) for (table= first_table; table; table= table->next_local->next_local)
{ {
if (check_access(thd, ALTER_ACL | DROP_ACL, table->db, if (check_access(thd, ALTER_ACL | DROP_ACL, table->db,
...@@ -3189,8 +3196,7 @@ mysql_execute_command(THD *thd) ...@@ -3189,8 +3196,7 @@ mysql_execute_command(THD *thd)
if (lex->only_view) if (lex->only_view)
first_table->skip_temporary= 1; first_table->skip_temporary= 1;
if (check_db_used(thd, all_tables) || if (check_access(thd, SELECT_ACL | EXTRA_ACL, first_table->db,
check_access(thd, SELECT_ACL | EXTRA_ACL, first_table->db,
&first_table->grant.privilege, 0, 0, &first_table->grant.privilege, 0, 0,
test(first_table->schema_table))) test(first_table->schema_table)))
goto error; goto error;
...@@ -3203,8 +3209,7 @@ mysql_execute_command(THD *thd) ...@@ -3203,8 +3209,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_CHECKSUM: case SQLCOM_CHECKSUM:
{ {
DBUG_ASSERT(first_table == all_tables && first_table != 0); DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) || if (check_table_access(thd, SELECT_ACL | EXTRA_ACL, all_tables, 0))
check_table_access(thd, SELECT_ACL | EXTRA_ACL, all_tables, 0))
goto error; /* purecov: inspected */ goto error; /* purecov: inspected */
res = mysql_checksum_table(thd, first_table, &lex->check_opt); res = mysql_checksum_table(thd, first_table, &lex->check_opt);
break; break;
...@@ -3212,8 +3217,7 @@ mysql_execute_command(THD *thd) ...@@ -3212,8 +3217,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_REPAIR: case SQLCOM_REPAIR:
{ {
DBUG_ASSERT(first_table == all_tables && first_table != 0); DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) || if (check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, 0))
check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, 0))
goto error; /* purecov: inspected */ goto error; /* purecov: inspected */
thd->enable_slow_log= opt_log_slow_admin_statements; thd->enable_slow_log= opt_log_slow_admin_statements;
res= mysql_repair_table(thd, first_table, &lex->check_opt); res= mysql_repair_table(thd, first_table, &lex->check_opt);
...@@ -3234,8 +3238,7 @@ mysql_execute_command(THD *thd) ...@@ -3234,8 +3238,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_CHECK: case SQLCOM_CHECK:
{ {
DBUG_ASSERT(first_table == all_tables && first_table != 0); DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) || if (check_table_access(thd, SELECT_ACL | EXTRA_ACL , all_tables, 0))
check_table_access(thd, SELECT_ACL | EXTRA_ACL , all_tables, 0))
goto error; /* purecov: inspected */ goto error; /* purecov: inspected */
thd->enable_slow_log= opt_log_slow_admin_statements; thd->enable_slow_log= opt_log_slow_admin_statements;
res = mysql_check_table(thd, first_table, &lex->check_opt); res = mysql_check_table(thd, first_table, &lex->check_opt);
...@@ -3246,8 +3249,7 @@ mysql_execute_command(THD *thd) ...@@ -3246,8 +3249,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_ANALYZE: case SQLCOM_ANALYZE:
{ {
DBUG_ASSERT(first_table == all_tables && first_table != 0); DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) || if (check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, 0))
check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, 0))
goto error; /* purecov: inspected */ goto error; /* purecov: inspected */
thd->enable_slow_log= opt_log_slow_admin_statements; thd->enable_slow_log= opt_log_slow_admin_statements;
res= mysql_analyze_table(thd, first_table, &lex->check_opt); res= mysql_analyze_table(thd, first_table, &lex->check_opt);
...@@ -3269,8 +3271,7 @@ mysql_execute_command(THD *thd) ...@@ -3269,8 +3271,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_OPTIMIZE: case SQLCOM_OPTIMIZE:
{ {
DBUG_ASSERT(first_table == all_tables && first_table != 0); DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) || if (check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, 0))
check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, 0))
goto error; /* purecov: inspected */ goto error; /* purecov: inspected */
thd->enable_slow_log= opt_log_slow_admin_statements; thd->enable_slow_log= opt_log_slow_admin_statements;
res= (specialflag & (SPECIAL_SAFE_MODE | SPECIAL_NO_NEW_FUNC)) ? res= (specialflag & (SPECIAL_SAFE_MODE | SPECIAL_NO_NEW_FUNC)) ?
...@@ -3690,7 +3691,7 @@ mysql_execute_command(THD *thd) ...@@ -3690,7 +3691,7 @@ mysql_execute_command(THD *thd)
break; break;
case SQLCOM_LOCK_TABLES: case SQLCOM_LOCK_TABLES:
unlock_locked_tables(thd); unlock_locked_tables(thd);
if (check_db_used(thd, all_tables) || end_active_trans(thd)) if (end_active_trans(thd))
goto error; goto error;
if (check_table_access(thd, LOCK_TABLES_ACL | SELECT_ACL, all_tables, 0)) if (check_table_access(thd, LOCK_TABLES_ACL | SELECT_ACL, all_tables, 0))
goto error; goto error;
...@@ -4167,7 +4168,7 @@ mysql_execute_command(THD *thd) ...@@ -4167,7 +4168,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_FLUSH: case SQLCOM_FLUSH:
{ {
bool write_to_binlog; bool write_to_binlog;
if (check_global_access(thd,RELOAD_ACL) || check_db_used(thd, all_tables)) if (check_global_access(thd,RELOAD_ACL))
goto error; goto error;
/* /*
reload_acl_and_cache() will tell us if we are allowed to write to the reload_acl_and_cache() will tell us if we are allowed to write to the
...@@ -4216,15 +4217,12 @@ mysql_execute_command(THD *thd) ...@@ -4216,15 +4217,12 @@ mysql_execute_command(THD *thd)
#endif #endif
case SQLCOM_HA_OPEN: case SQLCOM_HA_OPEN:
DBUG_ASSERT(first_table == all_tables && first_table != 0); DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) || if (check_table_access(thd, SELECT_ACL, all_tables, 0))
check_table_access(thd, SELECT_ACL, all_tables, 0))
goto error; goto error;
res= mysql_ha_open(thd, first_table, 0); res= mysql_ha_open(thd, first_table, 0);
break; break;
case SQLCOM_HA_CLOSE: case SQLCOM_HA_CLOSE:
DBUG_ASSERT(first_table == all_tables && first_table != 0); DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables))
goto error;
res= mysql_ha_close(thd, first_table); res= mysql_ha_close(thd, first_table);
break; break;
case SQLCOM_HA_READ: case SQLCOM_HA_READ:
...@@ -4234,8 +4232,6 @@ mysql_execute_command(THD *thd) ...@@ -4234,8 +4232,6 @@ mysql_execute_command(THD *thd)
if a user has no permissions to read a table, he won't be if a user has no permissions to read a table, he won't be
able to open it (with SQLCOM_HA_OPEN) in the first place. able to open it (with SQLCOM_HA_OPEN) in the first place.
*/ */
if (check_db_used(thd, all_tables))
goto error;
unit->set_limit(select_lex); unit->set_limit(select_lex);
res= mysql_ha_read(thd, first_table, lex->ha_read_mode, lex->ident.str, res= mysql_ha_read(thd, first_table, lex->ha_read_mode, lex->ident.str,
lex->insert_list, lex->ha_rkey_mode, select_lex->where, lex->insert_list, lex->ha_rkey_mode, select_lex->where,
...@@ -5734,27 +5730,6 @@ bool check_merge_table_access(THD *thd, char *db, ...@@ -5734,27 +5730,6 @@ bool check_merge_table_access(THD *thd, char *db,
} }
static bool check_db_used(THD *thd,TABLE_LIST *tables)
{
char *current_db= NULL;
for (; tables; tables= tables->next_global)
{
if (tables->db == NULL)
{
/*
This code never works and should be removed in 5.1. All tables
that are added to the list of tables should already have its
database field initialized properly (see st_lex::add_table_to_list).
*/
DBUG_ASSERT(0);
if (thd->copy_db_to(&current_db, 0))
return TRUE;
tables->db= current_db;
}
}
return FALSE;
}
/**************************************************************************** /****************************************************************************
Check stack size; Send error if there isn't enough stack to continue Check stack size; Send error if there isn't enough stack to continue
****************************************************************************/ ****************************************************************************/
...@@ -7450,8 +7425,7 @@ bool multi_delete_precheck(THD *thd, TABLE_LIST *tables) ...@@ -7450,8 +7425,7 @@ bool multi_delete_precheck(THD *thd, TABLE_LIST *tables)
/* sql_yacc guarantees that tables and aux_tables are not zero */ /* sql_yacc guarantees that tables and aux_tables are not zero */
DBUG_ASSERT(aux_tables != 0); DBUG_ASSERT(aux_tables != 0);
if (check_db_used(thd, tables) || check_db_used(thd,aux_tables) || if (check_table_access(thd, SELECT_ACL, tables, 0))
check_table_access(thd, SELECT_ACL, tables, 0))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
/* /*
...@@ -7551,8 +7525,7 @@ bool update_precheck(THD *thd, TABLE_LIST *tables) ...@@ -7551,8 +7525,7 @@ bool update_precheck(THD *thd, TABLE_LIST *tables)
my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0)); my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
DBUG_RETURN(check_db_used(thd, tables) || DBUG_RETURN(check_one_table_access(thd, UPDATE_ACL, tables));
check_one_table_access(thd, UPDATE_ACL, tables));
} }
...@@ -7614,8 +7587,6 @@ bool insert_precheck(THD *thd, TABLE_LIST *tables) ...@@ -7614,8 +7587,6 @@ bool insert_precheck(THD *thd, TABLE_LIST *tables)
my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0)); my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
if (check_db_used(thd, tables))
DBUG_RETURN(TRUE);
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
} }
......
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