Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-40309

Server crashes when a stored routine drops itself using a prepared statement

    XMLWordPrintable

Details

    • Can result in hang or crash

    Description

      SET sql_mode=ORACLE;
      DELIMITER $$;
      CREATE PROCEDURE p1() AS BEGIN
        EXECUTE IMMEDIATE 'DROP PROCEDURE p1';
      END$$
      DELIMITER ;$$
      CALL p1();
      

      Leads to:

      CS 13.1.0 dcb8fdc739c30622928f4d17fdef54f6dfbd34e6 (Debug, Clang 18.1.3-11) Build 30/06/2026

      Core was generated by `/test/MD300626-mariadb-13.1.0-linux-x86_64-dbg/bin/mariadbd --no-defaults --loo'.
      Program terminated with signal SIGSEGV, Segmentation fault.
      #0  0x0000613a2fa7d776 in Explain_query::have_query_plan (this=0x8f8f8f8f8f8f8f8f) at /test/13.1_dbg/sql/sql_explain.h:523
      523	  bool have_query_plan() { return insert_plan || upd_del_plan|| get_node(1) != NULL; }
      [Current thread is 1 (LWP 1698794)]
      (gdb) bt
      #0  0x0000613a2fa7d776 in Explain_query::have_query_plan (this=0x8f8f8f8f8f8f8f8f) at /test/13.1_dbg/sql/sql_explain.h:523
      #1  0x0000613a2faee164 in Prepared_statement::execute (this=0x6fc90c026e10, expanded_query=0x77c9fc4b79c0, open_cursor=false, result_arg=0x6fc90c026f60, cursor_arg=0x6fc90c026fd0)at /test/13.1_dbg/sql/sql_prepare.cc:5452
      #2  0x0000613a2faed3f9 in Prepared_statement::execute_loop (this=0x6fc90c026e10, expanded_query=0x77c9fc4b79c0, open_cursor=false, result_arg=0x6fc90c026f60, cursor_arg=0x6fc90c026fd0, instrs_set_placeholder=@0x77c9fc4b7cd0: {<Slice<unsigned int>> = {m_offset = 0, m_count = 0}, <No data fields>}, packet=0x0, packet_end=0x0)at /test/13.1_dbg/sql/sql_prepare.cc:4725
      #3  0x0000613a2faf08ab in Prepared_statement::execute_immediate (this=0x6fc90c026e10, query=0x6fc90c025860 '\217' <repeats 200 times>..., query_len=18, dynamic_open_cursor=false, result_arg=0x6fc90c026f60, cursor_arg=0x6fc90c026fd0, instrs_set_placeholder=@0x77c9fc4b7cd0: {<Slice<unsigned int>> = {m_offset = 0, m_count = 0}, <No data fields>}) at /test/13.1_dbg/sql/sql_prepare.cc:5544
      #4  0x0000613a2fae8112 in mysql_sql_stmt_execute_immediate (thd=0x6fc90c000d60, dynamic_open_cursor=false, result_arg=0x0, cursor_arg=0x0, instrs_set_placeholder=@0x77c9fc4b7cd0: {<Slice<unsigned int>> = {m_offset = 0, m_count = 0}, <No data fields>}) at /test/13.1_dbg/sql/sql_prepare.cc:2997
      #5  0x0000613a2fae7cb7 in mysql_sql_stmt_execute_immediate (thd=0x6fc90c000d60)at /test/13.1_dbg/sql/sql_prepare.cc:3020
      #6  0x0000613a2faa72ba in mysql_execute_command (thd=0x6fc90c000d60, is_called_from_prepared_stmt=false) at /test/13.1_dbg/sql/sql_parse.cc:3997
      #7  0x0000613a2fd79fe7 in sp_instr_stmt::exec_core (this=0x6fc90c025980, thd=0x6fc90c000d60, nextp=0x77c9fc4b97c8)at /test/13.1_dbg/sql/sp_instr.cc:1281
      #8  0x0000613a2fd774b6 in sp_lex_keeper::reset_lex_and_exec_core (this=0x6fc90c0259c0, thd=0x6fc90c000d60, nextp=0x77c9fc4b97c8, open_tables=false, instr=0x6fc90c025980, rerun_the_same_instr=false)at /test/13.1_dbg/sql/sp_instr.cc:420
      #9  0x0000613a2fd77c2c in sp_lex_keeper::validate_lex_and_exec_core (this=0x6fc90c0259c0, thd=0x6fc90c000d60, nextp=0x77c9fc4b97c8, open_tables=false, instr=0x6fc90c025980)at /test/13.1_dbg/sql/sp_instr.cc:599
      #10 0x0000613a2fd79259 in sp_instr_stmt::execute (this=0x6fc90c025980, thd=0x6fc90c000d60, nextp=0x77c9fc4b97c8)at /test/13.1_dbg/sql/sp_instr.cc:1183
      #11 0x0000613a2f976d6c in sp_head::execute (this=0x6fc90c024470, thd=0x6fc90c000d60, merge_da_on_success=true)at /test/13.1_dbg/sql/sp_head.cc:1332
      #12 0x0000613a2f97976e in sp_head::execute_procedure (this=0x6fc90c024470, thd=0x6fc90c000d60, args=0x6fc90c006280)at /test/13.1_dbg/sql/sp_head.cc:2369
      #13 0x0000613a2faa42e7 in do_execute_sp (thd=0x6fc90c000d60, sp=0x6fc90c024470)at /test/13.1_dbg/sql/sql_parse.cc:3084
      #14 0x0000613a2faa3e08 in Sql_cmd_call::execute (this=0x6fc90c01a690, thd=0x6fc90c000d60) at /test/13.1_dbg/sql/sql_parse.cc:3322
      #15 0x0000613a2fab0238 in mysql_execute_command (thd=0x6fc90c000d60, is_called_from_prepared_stmt=false) at /test/13.1_dbg/sql/sql_parse.cc:5905
      #16 0x0000613a2fa9f3b4 in mysql_parse (thd=0x6fc90c000d60, rawbuf=0x6fc90c01a3e0 "CALL p1()", length=10, parser_state=0x77c9fc4bbab0)at /test/13.1_dbg/sql/sql_parse.cc:7945
      #17 0x0000613a2fa9c6fd in dispatch_command (command=COM_QUERY, thd=0x6fc90c000d60, packet=0x6fc90c00b611 "CALL p1()", packet_length=10, blocking=true) at /test/13.1_dbg/sql/sql_parse.cc:1903
      #18 0x0000613a2fa9ff63 in do_command (thd=0x6fc90c000d60, blocking=true)at /test/13.1_dbg/sql/sql_parse.cc:1437
      #19 0x0000613a2fc9e6b9 in do_handle_one_connection (connect=0x613a3ffa5750, put_in_cache=true) at /test/13.1_dbg/sql/sql_connect.cc:1510
      #20 0x0000613a2fc9e45e in handle_one_connection (arg=0x613a3ff8a8e0)at /test/13.1_dbg/sql/sql_connect.cc:1422
      #21 0x000077ca0849caa4 in start_thread (arg=<optimized out>)at ./nptl/pthread_create.c:447
      #22 0x000077ca08529c6c in clone3 ()at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
      

      Bug Detection Matrix

          Rel    o/d  Build   Commit                                    UniqueID observed
      CS  10.6   dbg  210526  dae315a7b2bf8bd2fd0449467e711e5a2db26669  No bug found
      CS  10.6   opt  210526  dae315a7b2bf8bd2fd0449467e711e5a2db26669  No bug found
      CS  10.11  dbg  210526  6f1204ad849b72a997fd34ce44a522d76716c24d  SIGSEGV|Explain_query::have_query_plan|Prepared_statement::execute|Prepared_statement::execute_loop|Prepared_statement::execute_immediate
      CS  10.11  opt  210526  6f1204ad849b72a997fd34ce44a522d76716c24d  SIGSEGV|THD::is_error|sql_set_variables|LEX::restore_set_statement_var|Prepared_statement::execute
      CS  11.4   dbg  210526  19c59f2c79637cc360cc6d6b219ed9131124500d  SIGSEGV|THD::is_error|sql_set_variables|LEX::restore_set_statement_var|Prepared_statement::execute
      CS  11.4   opt  210526  19c59f2c79637cc360cc6d6b219ed9131124500d  SIGSEGV|cleanup_ftfuncs|st_select_lex::cleanup|st_select_lex_unit::cleanup|mysql_execute_command
      CS  11.8   dbg  210526  b494164767979072713fdeccc175ce3b3f5b1983  SIGSEGV|THD::is_error|sql_set_variables|LEX::restore_set_statement_var|Prepared_statement::execute
      CS  11.8   opt  210526  b494164767979072713fdeccc175ce3b3f5b1983  SIGSEGV|base_list_iterator::next|List_iterator<Item_func_match>::operator++|cleanup_ftfuncs|st_select_lex::cleanup
      CS  12.3   dbg  210526  4c33c5e48e31cdbf8c71a91e121eb65bf6ef285a  SIGSEGV|THD::is_error|sql_set_variables|LEX::restore_set_statement_var|Prepared_statement::execute
      CS  12.3   opt  210526  4c33c5e48e31cdbf8c71a91e121eb65bf6ef285a  SIGSEGV|THD::is_error|sql_set_variables|LEX::restore_set_statement_var|Prepared_statement::execute
      CS  13.0   dbg  210526  c8e8d33309606e682c98675d594dbd23ebc2ddf6  SIGSEGV|Explain_query::have_query_plan|Prepared_statement::execute|Prepared_statement::execute_loop|Prepared_statement::execute_immediate
      CS  13.0   opt  210526  c8e8d33309606e682c98675d594dbd23ebc2ddf6  SIGSEGV|THD::is_error|sql_set_variables|LEX::restore_set_statement_var|Prepared_statement::execute
      CS  13.1   dbg  300626  dcb8fdc739c30622928f4d17fdef54f6dfbd34e6  SIGSEGV|Explain_query::have_query_plan|Prepared_statement::execute|Prepared_statement::execute_loop|Prepared_statement::execute_immediate
      CS  13.1   opt  300626  dcb8fdc739c30622928f4d17fdef54f6dfbd34e6  SIGSEGV|base_list_iterator::next_fast|List_iterator_fast<set_var_base>::operator++|sql_set_variables|LEX::restore_set_statement_var
      ES  11.4   dbg  060526  90f707057d44f1b5c013a0c3672fd12f32ea7085  SIGSEGV|THD::is_error|sql_set_variables|LEX::restore_set_statement_var|Prepared_statement::execute
      ES  11.4   opt  060526  90f707057d44f1b5c013a0c3672fd12f32ea7085  SIGSEGV|cleanup_order|st_select_lex::cleanup|st_select_lex_unit::cleanup|mysql_execute_command
      ES  11.8   dbg  060526  1499789de285a8109d68d79347de0281865b28f4  SIGSEGV|THD::is_error|sql_set_variables|LEX::restore_set_statement_var|Prepared_statement::execute
      ES  11.8   opt  060526  1499789de285a8109d68d79347de0281865b28f4  SIGSEGV|Explain_query::have_query_plan|Prepared_statement::execute|Prepared_statement::execute_loop|Prepared_statement::execute_immediate
      

      Attachments

        Activity

          People

            bar Alexander Barkov
            ramesh Ramesh Sivaraman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 0d
                0d
                Remaining:
                Time Spent - 0.5h Remaining Estimate - 0.5d
                0.5d
                Logged:
                Time Spent - 0.5h Remaining Estimate - 0.5d
                0.5h

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.