1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

Bug#21432 Database/Table name limited to 64 bytes, not chars, problems with multi-byte

client/mysqldump.c:
  fixed typo
include/mysql_com.h:
  added new constants SYSTEM_CHARSET_MBMAXLEN, NAME_CHAR_LEN, USERNAME_CHAR_LENGTH
  increased NAME_LEN, USERNAME_LENGTH
mysql-test/r/create.result:
  result fix
mysql-test/r/grant.result:
  result fix
mysql-test/r/mysql.result:
  result fix
mysql-test/r/sp.result:
  result fix
mysql-test/t/create.test:
  test case
mysql-test/t/grant.test:
  test case
sql/events.cc:
  NAME_LEN is replaced with NAME_CHAR_LEN
sql/item_strfunc.h:
  fixed calculation of max_length
sql/mysql_priv.h:
  check_string_length function is replaced with check_string_byte_length
  added new function check_string_char_length
sql/sp.cc:
  NAME_LEN is replaced with NAME_CHAR_LEN
sql/sp_head.cc:
  NAME_LEN is replaced with NAME_CHAR_LEN
sql/sp_head.h:
  changed parameter of 'check_routine_name' function
sql/sql_class.cc:
  NAME_LEN is replaced with NAME_CHAR_LEN
sql/share/errmsg.txt:
  increased argument lengths according to new constants
sql/sql_parse.cc:
  removed unnecessary checks
  added function 'check_string_char_length'
sql/sql_plugin.cc:
  check that name is not longer than NAME_CHAR_LEN symbols
sql/sql_show.cc:
  NAME_LEN is replaced with NAME_CHAR_LEN
sql/sql_table.cc:
  check that key name is not longer than NAME_LEN symbols
sql/sql_udf.cc:
  check that udf name is not longer than NAME_CHAR_LEN symbols
sql/sql_yacc.yy:
  check that user name is not longer than USERNAME_CHAR_LENGTH symbols
sql/table.cc:
  check that db or table or column name is not longer than NAME_LEN symbols
storage/innobase/handler/ha_innodb.cc:
  removed unnecessary multiplication
tests/mysql_client_test.c:
  NAME_LEN is replaced with NAME_CHAR_LEN
This commit is contained in:
unknown
2007-04-03 16:13:27 +05:00
parent 6e5ca12b6a
commit fe074a726f
25 changed files with 2255 additions and 1997 deletions

View File

@ -3218,12 +3218,6 @@ end_with_restore_list:
is_schema_db(lex->spname->m_db.str)))
break;
if (lex->spname->m_name.length > NAME_LEN)
{
my_error(ER_TOO_LONG_IDENT, MYF(0), lex->spname->m_name.str);
/* this jumps to the end of the function and skips own messaging */
goto error;
}
if (lex->sql_command == SQLCOM_SHOW_CREATE_EVENT)
res= Events::get_instance()->show_create_event(thd, lex->spname->m_db,
@ -3996,11 +3990,6 @@ create_sp_error:
}
case SQLCOM_SHOW_CREATE_PROC:
{
if (lex->spname->m_name.length > NAME_LEN)
{
my_error(ER_TOO_LONG_IDENT, MYF(0), lex->spname->m_name.str);
goto error;
}
if (sp_show_create_procedure(thd, lex->spname) != SP_OK)
{ /* We don't distinguish between errors for now */
my_error(ER_SP_DOES_NOT_EXIST, MYF(0),
@ -4011,11 +4000,6 @@ create_sp_error:
}
case SQLCOM_SHOW_CREATE_FUNC:
{
if (lex->spname->m_name.length > NAME_LEN)
{
my_error(ER_TOO_LONG_IDENT, MYF(0), lex->spname->m_name.str);
goto error;
}
if (sp_show_create_function(thd, lex->spname) != SP_OK)
{ /* We don't distinguish between errors for now */
my_error(ER_SP_DOES_NOT_EXIST, MYF(0),
@ -4044,11 +4028,6 @@ create_sp_error:
{
sp_head *sp;
if (lex->spname->m_name.length > NAME_LEN)
{
my_error(ER_TOO_LONG_IDENT, MYF(0), lex->spname->m_name.str);
goto error;
}
if (lex->sql_command == SQLCOM_SHOW_PROC_CODE)
sp= sp_find_routine(thd, TYPE_ENUM_PROCEDURE, lex->spname,
&thd->sp_proc_cache, FALSE);
@ -5332,7 +5311,7 @@ bool mysql_test_parse_for_slave(THD *thd, char *inBuf, uint length)
** Return 0 if ok
******************************************************************************/
bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum_field_types type,
char *length, char *decimals,
uint type_modifier,
Item *default_value, Item *on_update_value,
@ -5345,14 +5324,15 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
LEX *lex= thd->lex;
DBUG_ENTER("add_field_to_list");
if (strlen(field_name) > NAME_LEN)
if (check_string_char_length(field_name, "", NAME_CHAR_LEN,
system_charset_info, 1))
{
my_error(ER_TOO_LONG_IDENT, MYF(0), field_name); /* purecov: inspected */
my_error(ER_TOO_LONG_IDENT, MYF(0), field_name->str); /* purecov: inspected */
DBUG_RETURN(1); /* purecov: inspected */
}
if (type_modifier & PRI_KEY_FLAG)
{
lex->col_list.push_back(new key_part_spec(field_name,0));
lex->col_list.push_back(new key_part_spec(field_name->str, 0));
lex->key_list.push_back(new Key(Key::PRIMARY, NullS,
&default_key_create_info,
0, lex->col_list));
@ -5360,7 +5340,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
}
if (type_modifier & (UNIQUE_FLAG | UNIQUE_KEY_FLAG))
{
lex->col_list.push_back(new key_part_spec(field_name,0));
lex->col_list.push_back(new key_part_spec(field_name->str, 0));
lex->key_list.push_back(new Key(Key::UNIQUE, NullS,
&default_key_create_info, 0,
lex->col_list));
@ -5380,7 +5360,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
!(((Item_func*)default_value)->functype() == Item_func::NOW_FUNC &&
type == MYSQL_TYPE_TIMESTAMP))
{
my_error(ER_INVALID_DEFAULT, MYF(0), field_name);
my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
DBUG_RETURN(1);
}
else if (default_value->type() == Item::NULL_ITEM)
@ -5389,20 +5369,20 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
if ((type_modifier & (NOT_NULL_FLAG | AUTO_INCREMENT_FLAG)) ==
NOT_NULL_FLAG)
{
my_error(ER_INVALID_DEFAULT, MYF(0), field_name);
my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
DBUG_RETURN(1);
}
}
else if (type_modifier & AUTO_INCREMENT_FLAG)
{
my_error(ER_INVALID_DEFAULT, MYF(0), field_name);
my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
DBUG_RETURN(1);
}
}
if (on_update_value && type != MYSQL_TYPE_TIMESTAMP)
{
my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name);
my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name->str);
DBUG_RETURN(1);
}
@ -5418,7 +5398,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
}
if (!(new_field= new create_field()) ||
new_field->init(thd, field_name, type, length, decimals, type_modifier,
new_field->init(thd, field_name->str, type, length, decimals, type_modifier,
default_value, on_update_value, comment, change,
interval_list, cs, uint_geom_type))
DBUG_RETURN(1);
@ -6970,26 +6950,62 @@ LEX_USER *get_current_user(THD *thd, LEX_USER *user)
/*
Check that length of a string does not exceed some limit.
Check that byte length of a string does not exceed some limit.
SYNOPSIS
check_string_length()
str string to be checked
err_msg error message to be displayed if the string is too long
max_length max length
check_string_byte_length()
str string to be checked
err_msg error message to be displayed if the string is too long
max_byte_length max length in bytes
RETURN
FALSE the passed string is not longer than max_length
TRUE the passed string is longer than max_length
NOTE
The function is not used in existing code but can be useful later?
*/
bool check_string_length(LEX_STRING *str, const char *err_msg,
uint max_length)
bool check_string_byte_length(LEX_STRING *str, const char *err_msg,
uint max_byte_length)
{
if (str->length <= max_length)
if (str->length <= max_byte_length)
return FALSE;
my_error(ER_WRONG_STRING_LENGTH, MYF(0), str->str, err_msg, max_length);
my_error(ER_WRONG_STRING_LENGTH, MYF(0), str->str, err_msg, max_byte_length);
return TRUE;
}
/*
Check that char length of a string does not exceed some limit.
SYNOPSIS
check_string_char_length()
str string to be checked
err_msg error message to be displayed if the string is too long
max_char_length max length in symbols
cs string charset
RETURN
FALSE the passed string is not longer than max_char_length
TRUE the passed string is longer than max_char_length
*/
bool check_string_char_length(LEX_STRING *str, const char *err_msg,
uint max_char_length, CHARSET_INFO *cs,
bool no_error)
{
int well_formed_error;
uint res= cs->cset->well_formed_len(cs, str->str, str->str + str->length,
max_char_length, &well_formed_error);
if (!well_formed_error && str->length == res)
return FALSE;
if (!no_error)
my_error(ER_WRONG_STRING_LENGTH, MYF(0), str->str, err_msg, max_char_length);
return TRUE;
}