diff options
author | unknown <pem@mysql.com> | 2005-10-26 15:34:57 +0200 |
---|---|---|
committer | unknown <pem@mysql.com> | 2005-10-26 15:34:57 +0200 |
commit | 9349f18b4491b55d8edc4a314131bd44108278ad (patch) | |
tree | 8438f02a4a9ed206e60f26923143418163c0ba22 /sql/sp.cc | |
parent | 10a889a577e1a09f29922ba20d7e8ad96449bb04 (diff) | |
download | mariadb-git-9349f18b4491b55d8edc4a314131bd44108278ad.tar.gz |
Fixed BUG#14233: Crash after tampering with the mysql.proc table
Added error checking for errors when attempting to use stored procedures
after the mysql.proc table has been dropped, corrupted, or tampered with.
Test cases were put in a separate file (sp-destruct.test).
mysql-test/t/sp.test:
Added comment.
sql/share/errmsg.txt:
New error message for corrupted mysql.proc table.
sql/sp.cc:
Check and return error code when caching stored routines.
In the case when no error message has been set, set one.
sql/sp.h:
Return error code from stored routine cache function.
sql/sql_base.cc:
Check for error from sp_cache_routines_* calls.
sql/sql_trigger.h:
Updated friend declaration for sp_cache_routines*.
mysql-test/r/sp-destruct.result:
New test file for destruction of the mysql.proc table.
mysql-test/t/sp-destruct.test:
New result file for destruction of the mysql.proc table.
Diffstat (limited to 'sql/sp.cc')
-rw-r--r-- | sql/sp.cc | 85 |
1 files changed, 63 insertions, 22 deletions
diff --git a/sql/sp.cc b/sql/sp.cc index 8386c5d58a2..6f08897b1af 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -1414,20 +1414,22 @@ static void sp_update_stmt_used_routines(THD *thd, LEX *lex, SQL_LIST *src) first_no_prelock - If true, don't add tables or cache routines used by the body of the first routine (i.e. *start) will be executed in non-prelocked mode. + tabs_changed - Set to TRUE some tables were added, FALSE otherwise NOTE If some function is missing this won't be reported here. Instead this fact will be discovered during query execution. RETURN VALUE - TRUE - some tables were added - FALSE - no tables were added. + 0 - success + -x - failure (error code, like SP_PARSE_ERROR et al) */ -static bool +static int sp_cache_routines_and_add_tables_aux(THD *thd, LEX *lex, Sroutine_hash_entry *start, - bool first_no_prelock) + bool first_no_prelock, bool *tabs_changed) { + int ret= 0; bool result= FALSE; bool first= TRUE; DBUG_ENTER("sp_cache_routines_and_add_tables_aux"); @@ -1453,12 +1455,35 @@ sp_cache_routines_and_add_tables_aux(THD *thd, LEX *lex, name.m_name.str+= 1; name.m_name.length= name.m_qname.length - name.m_db.length - 1; - if (db_find_routine(thd, type, &name, &sp) == SP_OK) + switch ((ret= db_find_routine(thd, type, &name, &sp))) { - if (type == TYPE_ENUM_FUNCTION) - sp_cache_insert(&thd->sp_func_cache, sp); - else - sp_cache_insert(&thd->sp_proc_cache, sp); + case SP_OK: + { + if (type == TYPE_ENUM_FUNCTION) + sp_cache_insert(&thd->sp_func_cache, sp); + else + sp_cache_insert(&thd->sp_proc_cache, sp); + } + break; + case SP_KEY_NOT_FOUND: + ret= SP_OK; + break; + case SP_OPEN_TABLE_FAILED: + /* + Force it to attempt opening it again on subsequent calls; + otherwise we will get one error message the first time, and + then ER_SP_PROC_TABLE_CORRUPT (below) on subsequent tries. + */ + mysql_proc_table_exists= 1; + /* Fall through */ + default: + /* + In some cases no error has been set (e.g. get field failed, + when the proc table has been tampered with). + */ + if (! thd->net.report_error) + my_error(ER_SP_PROC_TABLE_CORRUPT, MYF(0), ret); + break; } delete newlex; thd->lex= oldlex; @@ -1473,7 +1498,9 @@ sp_cache_routines_and_add_tables_aux(THD *thd, LEX *lex, } first= FALSE; } - DBUG_RETURN(result); + if (tabs_changed) + *tabs_changed= result; + DBUG_RETURN(ret); } @@ -1488,18 +1515,20 @@ sp_cache_routines_and_add_tables_aux(THD *thd, LEX *lex, lex - LEX representing statement first_no_prelock - If true, don't add tables or cache routines used by the body of the first routine (i.e. *start) + tabs_changed - Set to TRUE some tables were added, FALSE otherwise RETURN VALUE - TRUE - some tables were added - FALSE - no tables were added. + 0 - success + -x - failure (error code, like SP_PARSE_ERROR et al) */ -bool -sp_cache_routines_and_add_tables(THD *thd, LEX *lex, bool first_no_prelock) +int +sp_cache_routines_and_add_tables(THD *thd, LEX *lex, bool first_no_prelock, + bool *tabs_changed) { return sp_cache_routines_and_add_tables_aux(thd, lex, (Sroutine_hash_entry *)lex->sroutines_list.first, - first_no_prelock); + first_no_prelock, tabs_changed); } @@ -1513,16 +1542,21 @@ sp_cache_routines_and_add_tables(THD *thd, LEX *lex, bool first_no_prelock) thd - thread context lex - LEX representing statement aux_lex - LEX representing view + + RETURN VALUE + 0 - success + -x - failure (error code, like SP_PARSE_ERROR et al) */ -void +int sp_cache_routines_and_add_tables_for_view(THD *thd, LEX *lex, LEX *aux_lex) { Sroutine_hash_entry **last_cached_routine_ptr= (Sroutine_hash_entry **)lex->sroutines_list.next; sp_update_stmt_used_routines(thd, lex, &aux_lex->sroutines_list); - (void)sp_cache_routines_and_add_tables_aux(thd, lex, - *last_cached_routine_ptr, FALSE); + return sp_cache_routines_and_add_tables_aux(thd, lex, + *last_cached_routine_ptr, FALSE, + NULL); } @@ -1536,12 +1570,18 @@ sp_cache_routines_and_add_tables_for_view(THD *thd, LEX *lex, LEX *aux_lex) thd - thread context lex - LEX respresenting statement triggers - triggers of the table + + RETURN VALUE + 0 - success + -x - failure (error code, like SP_PARSE_ERROR et al) */ -void +int sp_cache_routines_and_add_tables_for_triggers(THD *thd, LEX *lex, Table_triggers_list *triggers) { + int ret= 0; + if (add_used_routine(lex, thd->stmt_arena, &triggers->sroutines_key)) { Sroutine_hash_entry **last_cached_routine_ptr= @@ -1559,10 +1599,11 @@ sp_cache_routines_and_add_tables_for_triggers(THD *thd, LEX *lex, } } } - (void)sp_cache_routines_and_add_tables_aux(thd, lex, - *last_cached_routine_ptr, - FALSE); + ret= sp_cache_routines_and_add_tables_aux(thd, lex, + *last_cached_routine_ptr, + FALSE, NULL); } + return ret; } |