Skip to content

Commit 21f5658

Browse files
committed
MDEV-32376 SHOW CREATE DATABASE statement crashes the server when db name contains some unicode characters, ASAN stack-buffer-overflow
Adding the test for the length of lex->name into show_create_db(). Without this test writes beyond the end of db_name_buff were possible upon a too long database name.
1 parent bf0aa99 commit 21f5658

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

mysql-test/main/create.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,4 +2061,11 @@ DROP TABLE t1;
20612061
#
20622062
CREATE TABLE t1 (id1 INT, id2 INT, primary key (id1), unique index (id2) visible);
20632063
drop table t1;
2064+
#
2065+
# MDEV-32376 SHOW CREATE DATABASE statement crashes the server when db name contains some unicode characters, ASAN stack-buffer-overflow
2066+
#
2067+
SET NAMES utf8mb3;
2068+
SHOW CREATE DATABASE `#testone#■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■`;
2069+
ERROR 42000: Incorrect database name '#testone#■■■■■■■■■■■■■■■■■■■■■■■■■■■■■...'
2070+
SET NAMES DEFAULT;
20642071
# End of 10.5 Test

mysql-test/main/create.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,4 +1935,13 @@ DROP TABLE t1;
19351935
CREATE TABLE t1 (id1 INT, id2 INT, primary key (id1), unique index (id2) visible);
19361936
drop table t1;
19371937

1938+
--echo #
1939+
--echo # MDEV-32376 SHOW CREATE DATABASE statement crashes the server when db name contains some unicode characters, ASAN stack-buffer-overflow
1940+
--echo #
1941+
1942+
SET NAMES utf8mb3;
1943+
--error ER_WRONG_DB_NAME
1944+
SHOW CREATE DATABASE `#testone#■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■`;
1945+
SET NAMES DEFAULT;
1946+
19381947
--echo # End of 10.5 Test

sql/sql_parse.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6637,6 +6637,23 @@ show_create_db(THD *thd, LEX *lex)
66376637
DBUG_EXECUTE_IF("4x_server_emul",
66386638
my_error(ER_UNKNOWN_ERROR, MYF(0)); return 1;);
66396639

6640+
#if MYSQL_VERSION_ID<=110301
6641+
/*
6642+
This piece of the code was added in 10.5 to fix MDEV-32376.
6643+
It should not get to 11.3 or higer, as MDEV-32376 was fixed
6644+
in a different way in 11.3.1 (see MDEV-31948).
6645+
*/
6646+
if (lex->name.length > sizeof(db_name_buff) - 1)
6647+
{
6648+
my_error(ER_WRONG_DB_NAME, MYF(0),
6649+
ErrConvString(lex->name.str, lex->name.length,
6650+
system_charset_info).ptr());
6651+
return 1;
6652+
}
6653+
#else
6654+
#error Remove this preprocessor-conditional code in 11.3.1+
6655+
#endif
6656+
66406657
db_name.str= db_name_buff;
66416658
db_name.length= lex->name.length;
66426659
strmov(db_name_buff, lex->name.str);

0 commit comments

Comments
 (0)