summaryrefslogtreecommitdiff
path: root/sql/sql_lex.cc
diff options
context:
space:
mode:
authorMarc Alff <marc.alff@sun.com>2008-07-14 15:41:30 -0600
committerMarc Alff <marc.alff@sun.com>2008-07-14 15:41:30 -0600
commite73e7bb9aec760edf7b142ac57696d44da149d86 (patch)
tree86658bba7f6c4fe4f438a97390da42762a277d3d /sql/sql_lex.cc
parent0617cf0f78fd79e6cf109720f708b98b35e34ce3 (diff)
downloadmariadb-git-e73e7bb9aec760edf7b142ac57696d44da149d86.tar.gz
Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on
build) The crash was caused by freeing the internal parser stack during the parser execution. This occured only for complex stored procedures, after reallocating the parser stack using my_yyoverflow(), with the following C call stack: - MYSQLparse() - any rule calling sp_head::restore_lex() - lex_end() - x_free(lex->yacc_yyss), xfree(lex->yacc_yyvs) The root cause is the implementation of stored procedures, which breaks the assumption from 4.1 that there is only one LEX structure per parser call. The solution is to separate the LEX structure into: - attributes that represent a statement (the current LEX structure), - attributes that relate to the syntax parser itself (Yacc_state), so that parsing multiple statements in stored programs can create multiple LEX structures while not changing the unique Yacc_state. Now, Yacc_state and the existing Lex_input_stream are aggregated into Parser_state, a structure that represent the complete state of the (Lexical + Syntax) parser. mysql-test/r/parser_stack.result: Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on build) mysql-test/t/parser_stack.test: Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on build) sql/sp.cc: Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on build) sql/sp_head.cc: Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on build) sql/sql_class.cc: Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on build) sql/sql_class.h: Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on build) sql/sql_lex.cc: Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on build) sql/sql_lex.h: Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on build) sql/sql_parse.cc: Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on build) sql/sql_prepare.cc: Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on build) sql/sql_trigger.cc: Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on build) sql/sql_view.cc: Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on build) sql/sql_yacc.yy: Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on build)
Diffstat (limited to 'sql/sql_lex.cc')
-rw-r--r--sql/sql_lex.cc20
1 files changed, 12 insertions, 8 deletions
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index a1bfc3edc6c..0cf7c11b447 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -192,7 +192,6 @@ void lex_start(THD *thd)
lex->select_lex.order_list.empty();
lex->select_lex.udf_list.empty();
lex->current_select= &lex->select_lex;
- lex->yacc_yyss=lex->yacc_yyvs=0;
lex->sql_command= lex->orig_sql_command= SQLCOM_END;
lex->duplicates= DUP_ERROR;
lex->ignore= 0;
@@ -210,11 +209,16 @@ void lex_start(THD *thd)
void lex_end(LEX *lex)
{
- DBUG_ENTER("lex_end");
- DBUG_PRINT("enter", ("lex: 0x%lx", (long) lex));
- x_free(lex->yacc_yyss);
- x_free(lex->yacc_yyvs);
- DBUG_VOID_RETURN;
+ /* Empty in 5.0, non empty in 5.1 */
+}
+
+Yacc_state::~Yacc_state()
+{
+ if (yacc_yyss)
+ {
+ x_free(yacc_yyss);
+ x_free(yacc_yyvs);
+ }
}
@@ -531,7 +535,7 @@ int MYSQLlex(void *arg, void *yythd)
uint length;
enum my_lex_states state;
THD *thd= (THD *)yythd;
- Lex_input_stream *lip= thd->m_lip;
+ Lex_input_stream *lip= & thd->m_parser_state->m_lip;
LEX *lex= thd->lex;
YYSTYPE *yylval=(YYSTYPE*) arg;
CHARSET_INFO *cs= thd->charset();
@@ -1781,7 +1785,7 @@ void Query_tables_list::destroy_query_tables_list()
*/
st_lex::st_lex()
- :result(0), yacc_yyss(0), yacc_yyvs(0),
+ :result(0),
sql_command(SQLCOM_END)
{
reset_query_tables_list(TRUE);