Skip to content

Commit d3443c8

Browse files
committed
MDEV-37056 : SIGSEGV in wsrep_check_sequence | mysql_alter_table
Problem was that thd->lex->m_sql_cmd is not always set especially when user has not provided ENGINE=xxx so requesting option_storage_engine_name from there is not safe. Fixed by accessing thd->lex->m_sql_cmd only when user has used ENGINE= and if not using ha_default_handlerton and requesting engine name after it.
1 parent 25253b7 commit d3443c8

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
connection node_2;
2+
connection node_1;
3+
connection node_1;
4+
SET SESSION wsrep_on=OFF;
5+
SET default_storage_engine=MYISAM;
6+
CREATE SEQUENCE t;
7+
SET SESSION wsrep_on=ON;
8+
CREATE INDEX idx ON t (a);
9+
ERROR HY000: Sequence 'test.t' table structure is invalid (Sequence tables cannot have any keys)
10+
DROP SEQUENCE t;
11+
SET default_storage_engine='MYISAM';
12+
CREATE SEQUENCE t INCREMENT BY 0 CACHE=0 ENGINE=InnoDB;
13+
CREATE INDEX c ON t (c);
14+
ERROR HY000: Sequence 'test.t' table structure is invalid (Sequence tables cannot have any keys)
15+
DROP SEQUENCE t;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--source include/galera_cluster.inc
2+
3+
--connection node_1
4+
SET SESSION wsrep_on=OFF;
5+
SET default_storage_engine=MYISAM;
6+
CREATE SEQUENCE t;
7+
SET SESSION wsrep_on=ON;
8+
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
9+
CREATE INDEX idx ON t (a);
10+
DROP SEQUENCE t;
11+
12+
SET default_storage_engine='MYISAM';
13+
CREATE SEQUENCE t INCREMENT BY 0 CACHE=0 ENGINE=InnoDB;
14+
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
15+
CREATE INDEX c ON t (c);
16+
17+
# cleanup
18+
DROP SEQUENCE t;

sql/sql_table.cc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5014,40 +5014,44 @@ bool wsrep_check_sequence(THD* thd,
50145014
const bool used_engine)
50155015
{
50165016
enum legacy_db_type db_type;
5017+
const LEX_CSTRING *engine_name;
50175018

50185019
DBUG_ASSERT(WSREP(thd));
50195020

50205021
if (used_engine)
50215022
{
50225023
db_type= thd->lex->create_info.db_type->db_type;
5024+
// Currently any dynamic storage engine is not possible to identify
5025+
// using DB_TYPE_XXXX and ENGINE=SEQUENCE is one of them.
5026+
// Therefore, we get storage engine name from lex.
5027+
engine_name=
5028+
thd->lex->m_sql_cmd->option_storage_engine_name()->name();
50235029
}
50245030
else
50255031
{
50265032
const handlerton *hton= ha_default_handlerton(thd);
50275033
db_type= hton->db_type;
5034+
engine_name= hton_name(hton);
50285035
}
50295036

50305037
// In Galera cluster we support only InnoDB sequences
50315038
if (db_type != DB_TYPE_INNODB)
50325039
{
5033-
// Currently any dynamic storage engine is not possible to identify
5034-
// using DB_TYPE_XXXX and ENGINE=SEQUENCE is one of them.
5035-
// Therefore, we get storage engine name from lex.
5036-
const LEX_CSTRING *tb_name= thd->lex->m_sql_cmd->option_storage_engine_name()->name();
50375040
// (1) CREATE TABLE ... ENGINE=SEQUENCE OR
50385041
// (2) ALTER TABLE ... ENGINE= OR
50395042
// Note in ALTER TABLE table->s->sequence != nullptr
50405043
// (3) CREATE SEQUENCE ... ENGINE=
50415044
if ((thd->lex->sql_command == SQLCOM_CREATE_TABLE &&
5042-
lex_string_eq(tb_name, STRING_WITH_LEN("SEQUENCE"))) ||
5045+
lex_string_eq(engine_name, STRING_WITH_LEN("SEQUENCE"))) ||
50435046
(thd->lex->sql_command == SQLCOM_ALTER_TABLE) ||
50445047
(thd->lex->sql_command == SQLCOM_CREATE_SEQUENCE))
50455048
{
50465049
my_error(ER_NOT_SUPPORTED_YET, MYF(0),
50475050
"non-InnoDB sequences in Galera cluster");
50485051
push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
50495052
ER_NOT_SUPPORTED_YET,
5050-
"ENGINE=%s not supported by Galera", tb_name->str);
5053+
"ENGINE=%s not supported by Galera",
5054+
engine_name->str);
50515055
return(true);
50525056
}
50535057
}

0 commit comments

Comments
 (0)