summaryrefslogtreecommitdiff
path: root/sql/sp.cc
diff options
context:
space:
mode:
authorunknown <pem@mysql.com>2005-11-25 17:09:26 +0100
committerunknown <pem@mysql.com>2005-11-25 17:09:26 +0100
commitd4088df5e9a02e714d85f79bec3ea97cdd8128c6 (patch)
tree025445f5fd80e1c80878febcdebb45817594e311 /sql/sp.cc
parentdf22630555ccf3b4cb6fc6254e846b87697b53c7 (diff)
downloadmariadb-git-d4088df5e9a02e714d85f79bec3ea97cdd8128c6.tar.gz
Fixed BUG#14233: Crash after tampering with the mysql.proc table
Post-review version. Some minor review fixes, but also changed the way some errors are handled: Don't return specific parse errors; instead always use the more general "table corrupt" error (amended accordingly). mysql-test/r/sp-destruct.result: Updated results. mysql-test/r/sp-error.result: Updated for fully qualified name in "no return" error message. mysql-test/t/sp-destruct.test: Adopted the more consistent error handling for a corrupted mysql.proc table. (No more "parse error" et al). sql/share/errmsg.txt: Changed ER_SP_PROC_TABLE_CORRUPT to be more explicit. sql/sp.cc: Review fixes. Changed the handling of parse errors, and added the routine name to the "table corrupt" error message. sql/sql_base.cc: Review changes: Change error tests and added comments. sql/sql_parse.cc: Mored ER_SP_NORETURN test of functions to sql_yacc.yy for more general error handling. sql/sql_yacc.yy: Mored ER_SP_NORETURN test of functions from sql_parse.cc for more general error handling.
Diffstat (limited to 'sql/sp.cc')
-rw-r--r--sql/sp.cc45
1 files changed, 28 insertions, 17 deletions
diff --git a/sql/sp.cc b/sql/sp.cc
index 6f08897b1af..49671a47bad 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -1420,8 +1420,8 @@ static void sp_update_stmt_used_routines(THD *thd, LEX *lex, SQL_LIST *src)
Instead this fact will be discovered during query execution.
RETURN VALUE
- 0 - success
- -x - failure (error code, like SP_PARSE_ERROR et al)
+ 0 - success
+ non-0 - failure
*/
static int
@@ -1430,7 +1430,7 @@ sp_cache_routines_and_add_tables_aux(THD *thd, LEX *lex,
bool first_no_prelock, bool *tabs_changed)
{
int ret= 0;
- bool result= FALSE;
+ int tabschnd= 0; /* Set if tables changed */
bool first= TRUE;
DBUG_ENTER("sp_cache_routines_and_add_tables_aux");
@@ -1478,11 +1478,21 @@ sp_cache_routines_and_add_tables_aux(THD *thd, LEX *lex,
/* 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);
+ Any error when loading an existing routine is either some problem
+ with the mysql.proc table, or a parse error because the contents
+ has been tampered with (in which case we clear that error).
+ */
+ if (ret == SP_PARSE_ERROR)
+ thd->clear_error();
+ if (!thd->net.report_error)
+ {
+ char n[NAME_LEN*2+2];
+
+ /* m_qname.str is not always \0 terminated */
+ memcpy(n, name.m_qname.str, name.m_qname.length);
+ n[name.m_qname.length]= '\0';
+ my_error(ER_SP_PROC_TABLE_CORRUPT, MYF(0), n, ret);
+ }
break;
}
delete newlex;
@@ -1493,13 +1503,14 @@ sp_cache_routines_and_add_tables_aux(THD *thd, LEX *lex,
if (!(first && first_no_prelock))
{
sp_update_stmt_used_routines(thd, lex, &sp->m_sroutines);
- result|= sp->add_used_tables_to_table_list(thd, &lex->query_tables_last);
+ tabschnd|=
+ sp->add_used_tables_to_table_list(thd, &lex->query_tables_last);
}
}
first= FALSE;
}
- if (tabs_changed)
- *tabs_changed= result;
+ if (tabs_changed) /* it can be NULL */
+ *tabs_changed= tabschnd;
DBUG_RETURN(ret);
}
@@ -1518,8 +1529,8 @@ sp_cache_routines_and_add_tables_aux(THD *thd, LEX *lex,
tabs_changed - Set to TRUE some tables were added, FALSE otherwise
RETURN VALUE
- 0 - success
- -x - failure (error code, like SP_PARSE_ERROR et al)
+ 0 - success
+ non-0 - failure
*/
int
@@ -1544,8 +1555,8 @@ sp_cache_routines_and_add_tables(THD *thd, LEX *lex, bool first_no_prelock,
aux_lex - LEX representing view
RETURN VALUE
- 0 - success
- -x - failure (error code, like SP_PARSE_ERROR et al)
+ 0 - success
+ non-0 - failure
*/
int
@@ -1572,8 +1583,8 @@ sp_cache_routines_and_add_tables_for_view(THD *thd, LEX *lex, LEX *aux_lex)
triggers - triggers of the table
RETURN VALUE
- 0 - success
- -x - failure (error code, like SP_PARSE_ERROR et al)
+ 0 - success
+ non-0 - failure
*/
int