List:Commits« Previous MessageNext Message »
From:dlenev Date:December 11 2005 12:26pm
Subject:bk commit into 5.0 tree (dlenev:1.1992) BUG#14863
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of dlenev. When dlenev does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1992 05/12/11 15:26:15 dlenev@stripped +3 -0
  Fix for bug #14863 "Triggers: crash if create and there is no current database".
  
  Now when we create or drop trigger we check that both trigger name and trigger
  table always have database part specified. Thus we give an error if it they
  are not specified explicitly or implicitly via current database.

  sql/sql_trigger.cc
    1.37 05/12/11 15:26:10 dlenev@stripped +17 -10
    mysql_create_or_drop_trigger():
      Now we check that both trigger name and trigger table have database
      part specified (explicitly or implicitly via current database. Note
      that in latter case sp_name::m_db is already set by parser).
    Table_triggers_list::create_trigger()/::add_table_for_trigger():
      Simplified method/function's code since now they can assume that
      sp_name::m_db is always filled now.
    trigname_file_parameters:
      Removed comment which is no longer true.

  mysql-test/t/trigger.test
    1.31 05/12/11 15:26:10 dlenev@stripped +15 -0
    Added test for bug #14863 "Triggers: crash if create and there is no current
    database".

  mysql-test/r/trigger.result
    1.25 05/12/11 15:26:10 dlenev@stripped +6 -0
    Added test for bug #14863 "Triggers: crash if create and there is no current
    database".

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	dlenev
# Host:	brandersnatch.site
# Root:	/home/dlenev/src/mysql-5.0-bg14836

--- 1.24/mysql-test/r/trigger.result	2005-11-23 02:12:33 +03:00
+++ 1.25/mysql-test/r/trigger.result	2005-12-11 15:26:10 +03:00
@@ -780,3 +780,9 @@
 CALL p2();
 drop procedure p2;
 drop table t1;
+create trigger t1_bi before insert on test.t1 for each row set @a:=0;
+ERROR 3D000: No database selected
+create trigger test.t1_bi before insert on t1 for each row set @a:=0;
+ERROR 3D000: No database selected
+drop trigger t1_bi;
+ERROR 3D000: No database selected

--- 1.30/mysql-test/t/trigger.test	2005-11-23 02:12:33 +03:00
+++ 1.31/mysql-test/t/trigger.test	2005-12-11 15:26:10 +03:00
@@ -13,6 +13,8 @@
 # Create additional connections used through test
 connect (addconroot1, localhost, root,,);
 connect (addconroot2, localhost, root,,);
+# Connection without current database set
+connect (addconwithoutdb, localhost, root,,*NO-ONE*);
 connection default;
 
 create table t1 (i int);
@@ -946,3 +948,16 @@
 drop procedure p2;
 drop table t1;
 
+#
+# Test for bug #14863 "Triggers: crash if create and there is no current
+# database". We should not crash and give proper error when database for
+# trigger or its table is not specified and there is no current database.
+#
+connection addconwithoutdb;
+--error ER_NO_DB_ERROR
+create trigger t1_bi before insert on test.t1 for each row set @a:=0;
+--error ER_NO_DB_ERROR
+create trigger test.t1_bi before insert on t1 for each row set @a:=0;
+--error ER_NO_DB_ERROR
+drop trigger t1_bi;
+connection default;

--- 1.36/sql/sql_trigger.cc	2005-12-07 17:01:08 +03:00
+++ 1.37/sql/sql_trigger.cc	2005-12-11 15:26:10 +03:00
@@ -78,10 +78,6 @@
 static File_option trigname_file_parameters[]=
 {
   {
-    /*
-      FIXME: Length specified for "trigger_table" key is erroneous, problem
-      caused by this are reported as BUG#14090 and should be fixed ASAP.
-    */
     {STRING_WITH_LEN("trigger_table")},
     offsetof(struct st_trigname, trigger_table),
    FILE_OPTIONS_ESTRING
@@ -155,6 +151,17 @@
     But do we want this ?
   */
 
+  /*
+    Note that once we will have check for TRIGGER privilege in place we won't
+    need second part of condition below, since check_access() function also
+    checks that db is specified.
+  */
+  if (!thd->lex->spname->m_db.length || create && !tables->db_length)
+  {
+    my_error(ER_NO_DB_ERROR, MYF(0));
+    DBUG_RETURN(TRUE);
+  }
+
   if (!create &&
       !(tables= add_table_for_trigger(thd, thd->lex->spname)))
     DBUG_RETURN(TRUE);
@@ -285,6 +292,9 @@
                      definer. The caller is responsible to provide memory for
                      storing LEX_STRING object.
 
+  NOTE
+    Assumes that trigger name is fully qualified.
+
   RETURN VALUE
     False - success
     True  - error
@@ -307,9 +317,7 @@
 
 
   /* Trigger must be in the same schema as target table. */
-  if (my_strcasecmp(table_alias_charset, table->s->db,
-                    lex->spname->m_db.str ? lex->spname->m_db.str :
-                                            thd->db))
+  if (my_strcasecmp(table_alias_charset, table->s->db, lex->spname->m_db.str))
   {
     my_error(ER_TRG_IN_WRONG_SCHEMA, MYF(0));
     return 1;
@@ -1010,7 +1018,6 @@
 
 static TABLE_LIST *add_table_for_trigger(THD *thd, sp_name *trig)
 {
-  const char *db= !trig->m_db.str ? thd->db : trig->m_db.str;
   LEX *lex= thd->lex;
   char path_buff[FN_REFLEN];
   LEX_STRING path;
@@ -1018,7 +1025,7 @@
   struct st_trigname trigname;
   DBUG_ENTER("add_table_for_trigger");
 
-  strxnmov(path_buff, FN_REFLEN, mysql_data_home, "/", db, "/",
+  strxnmov(path_buff, FN_REFLEN, mysql_data_home, "/", trig->m_db.str, "/",
            trig->m_name.str, trigname_file_ext, NullS);
   path.length= unpack_filename(path_buff, path_buff);
   path.str= path_buff;
@@ -1047,7 +1054,7 @@
   /* We need to reset statement table list to be PS/SP friendly. */
   lex->query_tables= 0;
   lex->query_tables_last= &lex->query_tables;
-  DBUG_RETURN(sp_add_to_query_tables(thd, lex, db,
+  DBUG_RETURN(sp_add_to_query_tables(thd, lex, trig->m_db.str,
                                      trigname.trigger_table.str, TL_WRITE));
 }
 
Thread
bk commit into 5.0 tree (dlenev:1.1992) BUG#14863dlenev11 Dec