From 7181ea56630d4e397f30b1073c3c806a2d59a530 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 6 Dec 2024 11:35:58 +1100 Subject: [PATCH] MDEV-33245 SIGSEGV in wsrep_check_sequence The segfault in wsrep_check_sequence is due to a null pointer deference on: db_type= thd->lex->create_info.db_type->db_type; Where create_info.db_type is null. This occured under a used_engine==true condition which is set in the calling function based on create_info.used_fields==HA_CREATE_USED_ENGINE. However the create_info.used_fields was a left over from the parsing of the previous failed CREATE TABLE where because of its failure, db_type wasn't populated. This is corrected by cleaning the create_info when we start to parse ALTER SEQUENCE statements. Other paths to wsrep_check_sequence is via CREATE SEQUENCE and CREATE TABLE LIKE which both initialize the create_info correctly. --- mysql-test/suite/galera/r/galera_sequences.result | 11 +++++++++++ mysql-test/suite/galera/t/galera_sequences.test | 15 +++++++++++++++ sql/sql_yacc.yy | 1 + 3 files changed, 27 insertions(+) diff --git a/mysql-test/suite/galera/r/galera_sequences.result b/mysql-test/suite/galera/r/galera_sequences.result index 1a5219c2d45..1f6b2bd6637 100644 --- a/mysql-test/suite/galera/r/galera_sequences.result +++ b/mysql-test/suite/galera/r/galera_sequences.result @@ -314,3 +314,14 @@ NEXTVAL(t) connection node_1; DROP TABLE t1; DROP SEQUENCE t; + +MDEV-33245 SIGSEGV in wsrep_check_sequence | Sql_cmd_alter_sequence::execute + +CREATE TABLE t (a INT) ENGINE=InnoDB; +INSERT INTO t VALUES (0); +CREATE TABLE t1 (c VARCHAR) ENGINE=InnoDB; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') ENGINE=InnoDB' at line 1 +ALTER SEQUENCE IF EXISTS t MINVALUE=1; +ERROR 42000: This version of MariaDB doesn't yet support 'CACHE without INCREMENT BY 0 in Galera cluster' +DROP TABLE t; +End of 10.5 tests diff --git a/mysql-test/suite/galera/t/galera_sequences.test b/mysql-test/suite/galera/t/galera_sequences.test index 53417055d7d..75a31b224b9 100644 --- a/mysql-test/suite/galera/t/galera_sequences.test +++ b/mysql-test/suite/galera/t/galera_sequences.test @@ -341,3 +341,18 @@ SELECT NEXTVAL(t); --connection node_1 DROP TABLE t1; DROP SEQUENCE t; + +--echo +--echo MDEV-33245 SIGSEGV in wsrep_check_sequence | Sql_cmd_alter_sequence::execute +--echo + +CREATE TABLE t (a INT) ENGINE=InnoDB; +INSERT INTO t VALUES (0); + +--error ER_PARSE_ERROR +CREATE TABLE t1 (c VARCHAR) ENGINE=InnoDB; +--error ER_NOT_SUPPORTED_YET +ALTER SEQUENCE IF EXISTS t MINVALUE=1; + +DROP TABLE t; +--echo End of 10.5 tests diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 9aab9f97fe0..7c2060d0b9d 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -7472,6 +7472,7 @@ alter: { LEX *lex= Lex; lex->sql_command= SQLCOM_ALTER_SEQUENCE; + lex->create_info.init(); DBUG_ASSERT(!lex->m_sql_cmd); if (Lex->main_select_push()) MYSQL_YYABORT;