[Commits] Rev 3490: Fixed bug #915222. in file:///home/igor/maria/maria-5.3-bug915222/

Igor Babaev igor at askmonty.org
Sat Apr 7 01:08:09 EEST 2012


At file:///home/igor/maria/maria-5.3-bug915222/

------------------------------------------------------------
revno: 3490
revision-id: igor at askmonty.org-20120406220809-qvp67dd8jz9kv5h0
parent: monty at askmonty.org-20120403124226-oaipfj7vrw0unyce
committer: Igor Babaev <igor at askmonty.org>
branch nick: maria-5.3-bug915222
timestamp: Fri 2012-04-06 15:08:09 -0700
message:
  Fixed bug #915222.
  This bug happened because the function find_field_in_view formed
  autogenerated names of view columns without a possibility to roll
  them back. In some situation it could cause memory misuses reported
  by valgrind or even crashes.
-------------- next part --------------
=== modified file 'mysql-test/r/view.result'
--- a/mysql-test/r/view.result	2012-02-03 11:32:29 +0000
+++ b/mysql-test/r/view.result	2012-04-06 22:08:09 +0000
@@ -4433,6 +4433,26 @@
 NULL	NULL	1	0
 DROP VIEW v2;
 DROP TABLE t1, t2, t3;
+#
+# BUG#915222: Valgrind complains or crashes with INSERT SELECT
+#              within a trigger that uses a view
+#
+CREATE TABLE t1 (a char(1));
+CREATE TABLE t2 (d int, e char(1));
+INSERT INTO t2 VALUES (13,'z');
+CREATE TRIGGER tr AFTER UPDATE ON t2
+FOR EACH ROW
+REPLACE INTO t3
+SELECT f, a AS alias FROM t3, v;
+CREATE TABLE t3 (f int, g char(8));
+CREATE VIEW v AS SELECT a, e FROM t2, t1;
+UPDATE t2 SET d=7;
+UPDATE t2 SET d=7;
+UPDATE t2 SET d=7;
+UPDATE t2 SET d=7;
+DROP TRIGGER tr;
+DROP VIEW v;
+DROP TABLE t1,t2,t3;
 # -----------------------------------------------------------------
 # -- End of 5.3 tests.
 # -----------------------------------------------------------------

=== modified file 'mysql-test/t/view.test'
--- a/mysql-test/t/view.test	2012-02-03 11:32:29 +0000
+++ b/mysql-test/t/view.test	2012-04-06 22:08:09 +0000
@@ -4365,6 +4365,35 @@
 DROP VIEW v2;
 DROP TABLE t1, t2, t3;
 
+--echo #
+--echo # BUG#915222: Valgrind complains or crashes with INSERT SELECT
+--echo #              within a trigger that uses a view
+--echo #
+
+CREATE TABLE t1 (a char(1));
+
+CREATE TABLE t2 (d int, e char(1));
+
+INSERT INTO t2 VALUES (13,'z');
+
+CREATE TRIGGER tr AFTER UPDATE ON t2
+  FOR EACH ROW
+  REPLACE INTO t3
+  SELECT f, a AS alias FROM t3, v;
+
+CREATE TABLE t3 (f int, g char(8));
+
+CREATE VIEW v AS SELECT a, e FROM t2, t1;
+
+UPDATE t2 SET d=7;
+UPDATE t2 SET d=7;
+UPDATE t2 SET d=7;
+UPDATE t2 SET d=7;
+
+DROP TRIGGER tr;
+DROP VIEW v;
+DROP TABLE t1,t2,t3;
+
 --echo # -----------------------------------------------------------------
 --echo # -- End of 5.3 tests.
 --echo # -----------------------------------------------------------------

=== modified file 'sql/item.cc'
--- a/sql/item.cc	2012-03-18 21:04:55 +0000
+++ b/sql/item.cc	2012-04-06 22:08:09 +0000
@@ -951,6 +951,21 @@
 }
 
 
+void Item::set_name_for_rollback(THD *thd, const char *str, uint length,
+                                 CHARSET_INFO *cs)
+{
+  char *old_name, *new_name; 
+  old_name= name;
+  set_name(str, length, cs);
+  new_name= name;
+  if (old_name != new_name)
+  {
+    name= old_name;
+    thd->change_item_tree((Item **) &name, (Item *) new_name);
+  }
+}
+
+
 /**
   @details
   This function is called when:

=== modified file 'sql/item.h'
--- a/sql/item.h	2012-02-26 08:19:07 +0000
+++ b/sql/item.h	2012-04-06 22:08:09 +0000
@@ -620,6 +620,8 @@
 #endif
   }		/*lint -e1509 */
   void set_name(const char *str, uint length, CHARSET_INFO *cs);
+  void set_name_for_rollback(THD *thd, const char *str, uint length,
+                             CHARSET_INFO *cs);
   void rename(char *new_name);
   void init_make_field(Send_field *tmp_field,enum enum_field_types type);
   virtual void cleanup();

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2012-03-23 16:22:39 +0000
+++ b/sql/sql_base.cc	2012-04-06 22:08:09 +0000
@@ -5988,15 +5988,22 @@
       */
       if (*ref && !(*ref)->is_autogenerated_name)
       {
-        if (register_tree_change &&
-            thd->stmt_arena->is_stmt_prepare_or_first_stmt_execute())
-          arena= thd->activate_stmt_arena_if_needed(&backup);
-        item->set_name((*ref)->name, (*ref)->name_length,
-                       system_charset_info);
-        item->real_item()->set_name((*ref)->name, (*ref)->name_length,
-                       system_charset_info);
-        if (arena)
-          thd->restore_active_arena(arena, &backup);
+        if (register_tree_change)
+	{
+          item->set_name_for_rollback(thd, (*ref)->name, 
+                                      (*ref)->name_length,
+                                      system_charset_info);
+          item->real_item()->set_name_for_rollback(thd, (*ref)->name,
+                                                   (*ref)->name_length,
+                                                   system_charset_info);
+        }
+        else
+	{
+          item->set_name((*ref)->name, (*ref)->name_length,
+                         system_charset_info);
+          item->real_item()->set_name((*ref)->name, (*ref)->name_length,
+                                      system_charset_info);
+        }
       }
       if (register_tree_change)
         thd->change_item_tree(ref, item);



More information about the commits mailing list