Commit 95cc85db authored by Jimmy Yang's avatar Jimmy Yang

Backport Bug #58643 InnoDB: too long table name. Also fix Bug #59312 examine

MAX_FULL_NAME_LEN in InnoDB to address possible insufficient name buffer

Bug #59312 Approved by Sunny Bains
parent c1fce59c
2011-01-06 The InnoDB Team
* row/row0merge.c:
Fix Bug#59312 Examine MAX_FULL_NAME_LEN in InnoDB to address
possible insufficient name buffer
2011-01-06 The InnoDB Team
* dict/dict0dict.c, handler/ha_innodb.cc, handler/i_s.cc,
include/univ.i:
Fix Bug#58643 InnoDB: too long table name
2010-11-11 The InnoDB Team 2010-11-11 The InnoDB Team
* thr/thr0loc.c, trx/trx0i_s.c: * thr/thr0loc.c, trx/trx0i_s.c:
Fix Bug#57802 Empty ASSERTION parameter passed to the HASH_SEARCH macro Fix Bug#57802 Empty ASSERTION parameter passed to the HASH_SEARCH macro
......
...@@ -932,7 +932,7 @@ dict_table_rename_in_cache( ...@@ -932,7 +932,7 @@ dict_table_rename_in_cache(
dict_foreign_t* foreign; dict_foreign_t* foreign;
dict_index_t* index; dict_index_t* index;
ulint fold; ulint fold;
char old_name[MAX_TABLE_NAME_LEN + 1]; char old_name[MAX_FULL_NAME_LEN + 1];
ut_ad(table); ut_ad(table);
ut_ad(mutex_own(&(dict_sys->mutex))); ut_ad(mutex_own(&(dict_sys->mutex)));
...@@ -944,7 +944,7 @@ dict_table_rename_in_cache( ...@@ -944,7 +944,7 @@ dict_table_rename_in_cache(
ut_print_timestamp(stderr); ut_print_timestamp(stderr);
fprintf(stderr, "InnoDB: too long table name: '%s', " fprintf(stderr, "InnoDB: too long table name: '%s', "
"max length is %d\n", table->name, "max length is %d\n", table->name,
MAX_TABLE_NAME_LEN); MAX_FULL_NAME_LEN);
ut_error; ut_error;
} }
...@@ -994,11 +994,11 @@ dict_table_rename_in_cache( ...@@ -994,11 +994,11 @@ dict_table_rename_in_cache(
ut_fold_string(old_name), table); ut_fold_string(old_name), table);
if (strlen(new_name) > strlen(table->name)) { if (strlen(new_name) > strlen(table->name)) {
/* We allocate MAX_TABLE_NAME_LEN+1 bytes here to avoid /* We allocate MAX_FULL_NAME_LEN + 1 bytes here to avoid
memory fragmentation, we assume a repeated calls of memory fragmentation, we assume a repeated calls of
ut_realloc() with the same size do not cause fragmentation */ ut_realloc() with the same size do not cause fragmentation */
ut_a(strlen(new_name) <= MAX_TABLE_NAME_LEN); ut_a(strlen(new_name) <= MAX_FULL_NAME_LEN);
table->name = ut_realloc(table->name, MAX_TABLE_NAME_LEN + 1); table->name = ut_realloc(table->name, MAX_FULL_NAME_LEN + 1);
} }
memcpy(table->name, new_name, strlen(new_name) + 1); memcpy(table->name, new_name, strlen(new_name) + 1);
......
...@@ -6009,6 +6009,16 @@ create_table_def( ...@@ -6009,6 +6009,16 @@ create_table_def(
DBUG_RETURN(HA_ERR_GENERIC); DBUG_RETURN(HA_ERR_GENERIC);
} }
/* MySQL does the name length check. But we do additional check
on the name length here */
if (strlen(table_name) > MAX_FULL_NAME_LEN) {
push_warning_printf(
(THD*) trx->mysql_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_TABLE_NAME,
"InnoDB: Table Name or Database Name is too long");
DBUG_RETURN(ER_TABLE_NAME);
}
n_cols = form->s->fields; n_cols = form->s->fields;
/* We pass 0 as the space id, and determine at a lower level the space /* We pass 0 as the space id, and determine at a lower level the space
......
...@@ -579,16 +579,7 @@ fill_innodb_locks_from_cache( ...@@ -579,16 +579,7 @@ fill_innodb_locks_from_cache(
for (i = 0; i < rows_num; i++) { for (i = 0; i < rows_num; i++) {
i_s_locks_row_t* row; i_s_locks_row_t* row;
char buf[MAX_FULL_NAME_LEN + 1];
/* note that the decoded database or table name is
never expected to be longer than NAME_LEN;
NAME_LEN for database name
2 for surrounding quotes around database name
NAME_LEN for table name
2 for surrounding quotes around table name
1 for the separating dot (.)
9 for the #mysql50# prefix */
char buf[2 * NAME_LEN + 14];
const char* bufend; const char* bufend;
char lock_trx_id[TRX_ID_MAX_LEN + 1]; char lock_trx_id[TRX_ID_MAX_LEN + 1];
......
...@@ -296,6 +296,18 @@ number does not include a terminating '\0'. InnoDB probably can handle ...@@ -296,6 +296,18 @@ number does not include a terminating '\0'. InnoDB probably can handle
longer names internally */ longer names internally */
#define MAX_TABLE_NAME_LEN 192 #define MAX_TABLE_NAME_LEN 192
/* The maximum length of a database name. Like MAX_TABLE_NAME_LEN this is
the MySQL's NAME_LEN, see check_and_convert_db_name(). */
#define MAX_DATABASE_NAME_LEN MAX_TABLE_NAME_LEN
/* MAX_FULL_NAME_LEN defines the full name path including the
database name and table name. In addition, 14 bytes is added for:
2 for surrounding quotes around table name
1 for the separating dot (.)
9 for the #mysql50# prefix */
#define MAX_FULL_NAME_LEN \
(MAX_TABLE_NAME_LEN + MAX_DATABASE_NAME_LEN + 14)
/* /*
UNIVERSAL TYPE DEFINITIONS UNIVERSAL TYPE DEFINITIONS
========================== ==========================
......
...@@ -2341,7 +2341,7 @@ row_merge_rename_tables( ...@@ -2341,7 +2341,7 @@ row_merge_rename_tables(
{ {
ulint err = DB_ERROR; ulint err = DB_ERROR;
pars_info_t* info; pars_info_t* info;
char old_name[MAX_TABLE_NAME_LEN + 1]; char old_name[MAX_FULL_NAME_LEN + 1];
ut_ad(trx->mysql_thread_id == os_thread_get_curr_id()); ut_ad(trx->mysql_thread_id == os_thread_get_curr_id());
ut_ad(old_table != new_table); ut_ad(old_table != new_table);
...@@ -2356,7 +2356,7 @@ row_merge_rename_tables( ...@@ -2356,7 +2356,7 @@ row_merge_rename_tables(
ut_print_timestamp(stderr); ut_print_timestamp(stderr);
fprintf(stderr, "InnoDB: too long table name: '%s', " fprintf(stderr, "InnoDB: too long table name: '%s', "
"max length is %d\n", old_table->name, "max length is %d\n", old_table->name,
MAX_TABLE_NAME_LEN); MAX_FULL_NAME_LEN);
ut_error; ut_error;
} }
......
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