From 76073d7bf5878e77435406e3b24346a547ea1e14 Mon Sep 17 00:00:00 2001 From: "pem@mysql.comhem.se" <> Date: Tue, 31 May 2005 18:36:32 +0200 Subject: [PATCH] Fixed BUG#9529: Stored Procedures: No Warning on truncation of procedure name during creation. Although it returns an error, consistent with the behaviour for other objects. (Unclear why we would allow the creation of SPs with truncated names.) --- mysql-test/r/sp-error.result | 4 ++++ mysql-test/t/sp-error.test | 10 ++++++++++ sql/sp.cc | 9 +++++++++ sql/sp.h | 1 + sql/sql_parse.cc | 6 ++++++ 5 files changed, 30 insertions(+) diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result index 5eb651e2fca..ccdb46f10d0 100644 --- a/mysql-test/r/sp-error.result +++ b/mysql-test/r/sp-error.result @@ -654,4 +654,8 @@ flush tables; return 5; end| ERROR 0A000: FLUSH is not allowed in stored procedures +create procedure bug9529_90123456789012345678901234567890123456789012345678901234567890() +begin +end| +ERROR 42000: Identifier name 'bug9529_90123456789012345678901234567890123456789012345678901234567890' is too long drop table t1| diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test index 78a6cdd49e1..a2a43110b54 100644 --- a/mysql-test/t/sp-error.test +++ b/mysql-test/t/sp-error.test @@ -920,6 +920,16 @@ begin end| +# +# BUG#9529: Stored Procedures: No Warning on truncation of procedure name +# during creation. +# +--error ER_TOO_LONG_IDENT +create procedure bug9529_90123456789012345678901234567890123456789012345678901234567890() +begin +end| + + # # BUG#NNNN: New bug synopsis # diff --git a/sql/sp.cc b/sql/sp.cc index a5b1f062456..4f89d6ba6da 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -120,6 +120,10 @@ db_find_routine_aux(THD *thd, int type, sp_name *name, 'db', 'name' and 'type' and the first key is the primary key over the same fields. */ + if (name->m_name.length > table->field[1]->field_length) + { + DBUG_RETURN(SP_KEY_NOT_FOUND); + } table->field[0]->store(name->m_db.str, name->m_db.length, &my_charset_bin); table->field[1]->store(name->m_name.str, name->m_name.length, &my_charset_bin); @@ -389,6 +393,11 @@ db_create_routine(THD *thd, int type, sp_head *sp) ret= SP_GET_FIELD_FAILED; goto done; } + if (sp->m_name.length > table->field[MYSQL_PROC_FIELD_NAME]->field_length) + { + ret= SP_BAD_IDENTIFIER; + goto done; + } table->field[MYSQL_PROC_FIELD_DB]-> store(sp->m_db.str, sp->m_db.length, system_charset_info); table->field[MYSQL_PROC_FIELD_NAME]-> diff --git a/sql/sp.h b/sql/sp.h index 00dd8416c1d..16d79026132 100644 --- a/sql/sp.h +++ b/sql/sp.h @@ -28,6 +28,7 @@ #define SP_PARSE_ERROR -6 #define SP_INTERNAL_ERROR -7 #define SP_NO_DB_ERROR -8 +#define SP_BAD_IDENTIFIER -9 /* Drop all routines in database 'db' */ int diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index b36f88cf8c8..2191eba2f3e 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4019,6 +4019,12 @@ mysql_execute_command(THD *thd) delete lex->sphead; lex->sphead= 0; goto error; + case SP_BAD_IDENTIFIER: + my_error(ER_TOO_LONG_IDENT, MYF(0), name); + lex->unit.cleanup(); + delete lex->sphead; + lex->sphead= 0; + goto error; default: my_error(ER_SP_STORE_FAILED, MYF(0), SP_TYPE_STRING(lex), name); lex->unit.cleanup(); -- 2.30.9