Commit 26907e7e authored by Alexander Barkov's avatar Alexander Barkov

MDEV-22941 Assertion `idx < array.elements' failed in Dynamic_array<st_mysql_const_lex_string*>::at

The code in fill_schema_schemata() did not take into account that
make_db_list() can leave empty db_names if the requested database
name was too long, so the call for db_names.at(0) crashed on assert.

- Moving the code testing if the database directory exists
  into a separate function verify_database_directory_exists()
- Modifying the test to check if db_names is not empty
parent bf74f7f9
...@@ -2101,3 +2101,13 @@ column_name ...@@ -2101,3 +2101,13 @@ column_name
c1 c1
c2 c2
DROP TABLE tt1, tt2; DROP TABLE tt1, tt2;
#
# MDEV-13242 Wrong results for queries with row constructors and information_schema
#
SELECT SCHEMA_NAME from information_schema.schemata where schema_name='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
SCHEMA_NAME
SELECT SCHEMA_NAME from information_schema.schemata where schema_name=REPEAT('a',193);
SCHEMA_NAME
#
# End of 10.1 tests
#
...@@ -1936,3 +1936,15 @@ SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (t ...@@ -1936,3 +1936,15 @@ SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (t
SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (table_name='tt1' AND column_name='c1') OR (table_name='tt2' AND column_name='c2'); SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (table_name='tt1' AND column_name='c1') OR (table_name='tt2' AND column_name='c2');
SELECT column_name FROM information_schema.columns WHERE (table_name, column_name) IN (('tt1','c1'),('tt2', 'c2')) ORDER BY column_name; SELECT column_name FROM information_schema.columns WHERE (table_name, column_name) IN (('tt1','c1'),('tt2', 'c2')) ORDER BY column_name;
DROP TABLE tt1, tt2; DROP TABLE tt1, tt2;
--echo #
--echo # MDEV-13242 Wrong results for queries with row constructors and information_schema
--echo #
SELECT SCHEMA_NAME from information_schema.schemata where schema_name='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
SELECT SCHEMA_NAME from information_schema.schemata where schema_name=REPEAT('a',193);
--echo #
--echo # End of 10.1 tests
--echo #
...@@ -4953,6 +4953,29 @@ bool store_schema_shemata(THD* thd, TABLE *table, LEX_STRING *db_name, ...@@ -4953,6 +4953,29 @@ bool store_schema_shemata(THD* thd, TABLE *table, LEX_STRING *db_name,
} }
/*
Check if the specified database exists on disk.
@param dbname - the database name
@retval true - on error, the database directory does not exists
@retval false - on success, the database directory exists
*/
static bool verify_database_directory_exists(const LEX_STRING &dbname)
{
DBUG_ENTER("verity_database_exists");
char path[FN_REFLEN + 16];
uint path_len;
MY_STAT stat_info;
if (!dbname.str[0])
DBUG_RETURN(true); // Empty database name: does not exits.
path_len= build_table_filename(path, sizeof(path) - 1, dbname.str, "", "", 0);
path[path_len - 1]= 0;
if (!mysql_file_stat(key_file_misc, path, &stat_info, MYF(0)))
DBUG_RETURN(true); // The database directory was not found: does not exists.
DBUG_RETURN(false); // The database directory was found.
}
int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond) int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond)
{ {
/* /*
...@@ -4981,19 +5004,10 @@ int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond) ...@@ -4981,19 +5004,10 @@ int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond)
If we have lookup db value we should check that the database exists If we have lookup db value we should check that the database exists
*/ */
if(lookup_field_vals.db_value.str && !lookup_field_vals.wild_db_value && if(lookup_field_vals.db_value.str && !lookup_field_vals.wild_db_value &&
db_names.at(0) != &INFORMATION_SCHEMA_NAME) (!db_names.elements() /* The database name was too long */||
{ (db_names.at(0) != &INFORMATION_SCHEMA_NAME &&
char path[FN_REFLEN+16]; verify_database_directory_exists(lookup_field_vals.db_value))))
uint path_len; DBUG_RETURN(0);
MY_STAT stat_info;
if (!lookup_field_vals.db_value.str[0])
DBUG_RETURN(0);
path_len= build_table_filename(path, sizeof(path) - 1,
lookup_field_vals.db_value.str, "", "", 0);
path[path_len-1]= 0;
if (!mysql_file_stat(key_file_misc, path, &stat_info, MYF(0)))
DBUG_RETURN(0);
}
for (size_t i=0; i < db_names.elements(); i++) for (size_t i=0; i < db_names.elements(); i++)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment