summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <vva@eagle.mysql.r18.ru>2004-03-05 22:13:33 +0400
committerunknown <vva@eagle.mysql.r18.ru>2004-03-05 22:13:33 +0400
commit8550c7abebe81d102fb74bd82b1db2b098e22330 (patch)
treee3022f508e6b88ed24bf0ed9eb0eda2843a7a121
parent15d8e9d06435f582125657f03e8ee294c04c0995 (diff)
downloadmariadb-git-8550c7abebe81d102fb74bd82b1db2b098e22330.tar.gz
fixed Bug #2985
"Table truncated when creating another table name with Spaces" added to check_db_name, check_table_name and check_column_name test for end space mysql-test/r/create.result: added test for Bug #2985 "Table truncated when creating another table name with Spaces" mysql-test/t/create.test: added test for Bug #2985 "Table truncated when creating another table name with Spaces" sql/sql_db.cc: cancel strip end spaces for database name sql/sql_parse.cc: cancel strip end spaces for database name sql/table.cc: added to check_db_name, check_table_name and check_column_name test for end space
-rw-r--r--mysql-test/r/create.result6
-rw-r--r--mysql-test/t/create.test12
-rw-r--r--sql/sql_db.cc2
-rw-r--r--sql/sql_parse.cc12
-rw-r--r--sql/table.cc28
5 files changed, 49 insertions, 11 deletions
diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result
index 627913939fb..22743782484 100644
--- a/mysql-test/r/create.result
+++ b/mysql-test/r/create.result
@@ -216,3 +216,9 @@ a b
0 2
3 4
drop table t1;
+create table `t1 `(a int);
+Incorrect table name 't1 '
+create database `db1 `;
+Incorrect database name 'db1 '
+create table t1(`a ` int);
+Incorrect column name 'a '
diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test
index 8aee586268f..94c2f24dffc 100644
--- a/mysql-test/t/create.test
+++ b/mysql-test/t/create.test
@@ -179,3 +179,15 @@ create table if not exists t1 select 3 as 'a',4 as 'b';
create table if not exists t1 select 3 as 'a',3 as 'b';
select * from t1;
drop table t1;
+
+#
+# Test for Bug #2985
+# "Table truncated when creating another table name with Spaces"
+#
+
+--error 1103
+create table `t1 `(a int);
+--error 1102
+create database `db1 `;
+--error 1166;
+create table t1(`a ` int);
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index ca9989d986c..a0b2ebdbff8 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -376,7 +376,7 @@ bool mysql_change_db(THD *thd,const char *name)
ulong db_access;
DBUG_ENTER("mysql_change_db");
- if (!dbname || !(db_length=strip_sp(dbname)))
+ if (!dbname || !(db_length= strlength(dbname)))
{
x_free(dbname); /* purecov: inspected */
send_error(&thd->net,ER_NO_DB_ERROR); /* purecov: inspected */
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index ac3ccd4fc62..bab59a162be 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1123,8 +1123,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
statistic_increment(com_stat[SQLCOM_CREATE_DB],&LOCK_status);
// null test to handle EOM
- if (!db || !strip_sp(db) || !(alias= thd->strdup(db)) ||
- check_db_name(db))
+ if (!db || !(alias= thd->strdup(db)) || check_db_name(db))
{
net_printf(&thd->net,ER_WRONG_DB_NAME, db ? db : "NULL");
break;
@@ -1140,8 +1139,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
statistic_increment(com_stat[SQLCOM_DROP_DB],&LOCK_status);
char *db=thd->strdup(packet), *alias;
// null test to handle EOM
- if (!db || !strip_sp(db) || !(alias= thd->strdup(db)) ||
- check_db_name(db))
+ if (!db || !(alias= thd->strdup(db)) || check_db_name(db))
{
net_printf(&thd->net,ER_WRONG_DB_NAME, db ? db : "NULL");
break;
@@ -2320,8 +2318,7 @@ mysql_execute_command(void)
case SQLCOM_CREATE_DB:
{
char *alias;
- if (!strip_sp(lex->name) || !(alias=thd->strdup(lex->name)) ||
- check_db_name(lex->name))
+ if (!(alias=thd->strdup(lex->name)) || check_db_name(lex->name))
{
net_printf(&thd->net,ER_WRONG_DB_NAME, lex->name);
break;
@@ -2350,8 +2347,7 @@ mysql_execute_command(void)
case SQLCOM_DROP_DB:
{
char *alias;
- if (!strip_sp(lex->name) || !(alias=thd->strdup(lex->name)) ||
- check_db_name(lex->name))
+ if (!(alias=thd->strdup(lex->name)) || check_db_name(lex->name))
{
net_printf(&thd->net,ER_WRONG_DB_NAME, lex->name);
break;
diff --git a/sql/table.cc b/sql/table.cc
index a90220fa55b..ffe901b9061 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -1139,7 +1139,8 @@ char *get_field(MEM_ROOT *mem, TABLE *table, uint fieldnr)
bool check_db_name(char *name)
{
- char *start=name;
+ char *start=name;
+ bool space= false;
if (lower_case_table_names)
casedn_str(name);
@@ -1147,6 +1148,7 @@ bool check_db_name(char *name)
while (*name)
{
#if defined(USE_MB) && defined(USE_MB_IDENT)
+ space= my_isspace(default_charset_info, *name);
if (use_mb(default_charset_info))
{
int len=my_ismbchar(default_charset_info, name, name+MBMAXLEN);
@@ -1156,19 +1158,24 @@ bool check_db_name(char *name)
continue;
}
}
+#else
+ space= *name==' ';
#endif
if (*name == '/' || *name == '\\' || *name == FN_LIBCHAR ||
*name == FN_EXTCHAR)
return 1;
name++;
}
- return (uint) (name - start) > NAME_LEN;
+ if (space)
+ return 1;
+ return name[-1]==' ' || (uint) (name - start) > NAME_LEN;
}
/*
Allow anything as a table name, as long as it doesn't contain an
a '/', or a '.' character
+ or ' ' at the end
returns 1 on error
*/
@@ -1178,10 +1185,17 @@ bool check_table_name(const char *name, uint length)
const char *end= name+length;
if (!length || length > NAME_LEN)
return 1;
+#if defined(USE_MB) && defined(USE_MB_IDENT)
+ bool space= false;
+#else
+ if (name[length-1]==' ')
+ return 1;
+#endif
while (name != end)
{
#if defined(USE_MB) && defined(USE_MB_IDENT)
+ space= my_isspace(default_charset_info, *name);
if (use_mb(default_charset_info))
{
int len=my_ismbchar(default_charset_info, name, end);
@@ -1196,16 +1210,22 @@ bool check_table_name(const char *name, uint length)
return 1;
name++;
}
+#if defined(USE_MB) && defined(USE_MB_IDENT)
+ if (space)
+ return 1;
+#endif
return 0;
}
bool check_column_name(const char *name)
{
const char *start= name;
+ bool space= false;
while (*name)
{
#if defined(USE_MB) && defined(USE_MB_IDENT)
+ space= my_isspace(default_charset_info, *name);
if (use_mb(default_charset_info))
{
int len=my_ismbchar(default_charset_info, name, name+MBMAXLEN);
@@ -1215,11 +1235,15 @@ bool check_column_name(const char *name)
continue;
}
}
+#else
+ space= *name==' ';
#endif
if (*name == NAMES_SEP_CHAR)
return 1;
name++;
}
+ if (space)
+ return 1;
/* Error if empty or too long column name */
return (name == start || (uint) (name - start) > NAME_LEN);
}