• Marc Alff's avatar
    Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on · 5ac2bf7c
    Marc Alff authored
    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)
    5ac2bf7c
sql_class.cc 64.1 KB