List:Commits« Previous MessageNext Message »
From:Alexander Nozdrin Date:April 25 2011 3:22pm
Subject:bzr commit into mysql-5.1 branch (alexander.nozdrin:3670) Bug#12394306
View as plain text  
#At file:///home/alik/MySQL/bzr/00/bug_events/mysql-5.1/ based on revid:mattias.jonsson@stripped

 3670 Alexander Nozdrin	2011-04-25
      Patch for Bug#12394306: the sever may crash if mysql.event is corrupted.
      
      The problem was that wrong structure of mysql.event was not detected and
      the server continued to use wrongly-structured data.
      
      The fix is to check if the created/modified columns have
      the MYSQL_TYPE_TIMESTAMP type before using them.

    modified:
      mysql-test/r/events_1.result
      mysql-test/t/events_1.test
      sql/event_data_objects.cc
      sql/event_db_repository.cc
=== modified file 'mysql-test/r/events_1.result'
--- a/mysql-test/r/events_1.result	2008-02-20 13:40:46 +0000
+++ b/mysql-test/r/events_1.result	2011-04-25 15:22:23 +0000
@@ -309,7 +309,7 @@ ERROR HY000: Unknown event 'intact_check
 DROP EVENT no_such_event;
 ERROR HY000: Unknown event 'no_such_event'
 CREATE EVENT intact_check_1 ON SCHEDULE EVERY 5 HOUR DO SELECT 5;
-ERROR HY000: Failed to store event name. Error code 2 from storage engine.
+ERROR HY000: Failed to open mysql.event
 ALTER EVENT intact_check_1 ON SCHEDULE EVERY 8 HOUR DO SELECT 8;
 ERROR HY000: Unknown event 'intact_check_1'
 ALTER EVENT intact_check_1 RENAME TO intact_check_2;
@@ -425,4 +425,42 @@ CREATE TABLE mysql.event like event_like
 DROP TABLE event_like;
 SHOW EVENTS;
 Db	Name	Definer	Time zone	Type	Execute at	Interval value	Interval field	Starts	Ends	Status	Originator	character_set_client	collation_connection	Database Collation
+
+#
+# Bug#12394306: the sever may crash if mysql.event is corrupted
+#
+
+CREATE EVENT ev1 ON SCHEDULE EVERY 5 HOUR DO SELECT 5;
+ALTER EVENT ev1 ON SCHEDULE EVERY 8 HOUR DO SELECT 8;
+
+CREATE TABLE event_original LIKE mysql.event;
+INSERT INTO event_original SELECT * FROM mysql.event;
+
+ALTER TABLE mysql.event MODIFY modified CHAR(1);
+Warnings:
+Warning	1265	Data truncated for column 'modified' at row 1
+
+SHOW EVENTS;
+ERROR HY000: Cannot load from mysql.event. The table is probably corrupted
+
+SELECT event_name, created, last_altered FROM information_schema.events;
+ERROR HY000: Cannot load from mysql.event. The table is probably corrupted
+
+CREATE EVENT ev2 ON SCHEDULE EVERY 5 HOUR DO SELECT 5;
+ERROR HY000: Failed to open mysql.event
+
+ALTER EVENT ev1 ON SCHEDULE EVERY 9 HOUR DO SELECT 9;
+ERROR HY000: Failed to open mysql.event
+
+DROP TABLE mysql.event;
+RENAME TABLE event_original TO mysql.event;
+
+DROP EVENT ev1;
+
+SHOW EVENTS;
+Db	Name	Definer	Time zone	Type	Execute at	Interval value	Interval field	Starts	Ends	Status	Originator	character_set_client	collation_connection	Database Collation
+
+# 
+# End of tests
+#
 drop database events_test;

=== modified file 'mysql-test/t/events_1.test'
--- a/mysql-test/t/events_1.test	2008-02-22 20:28:59 +0000
+++ b/mysql-test/t/events_1.test	2011-04-25 15:22:23 +0000
@@ -310,7 +310,7 @@ SELECT event_name FROM INFORMATION_SCHEM
 SHOW CREATE EVENT intact_check;
 --error ER_EVENT_DOES_NOT_EXIST
 DROP EVENT no_such_event;
---error ER_EVENT_STORE_FAILED
+--error ER_EVENT_OPEN_TABLE_FAILED
 CREATE EVENT intact_check_1 ON SCHEDULE EVERY 5 HOUR DO SELECT 5;
 --error ER_EVENT_DOES_NOT_EXIST
 ALTER EVENT intact_check_1 ON SCHEDULE EVERY 8 HOUR DO SELECT 8;
@@ -407,9 +407,54 @@ CREATE TABLE mysql.event like event_like
 DROP TABLE event_like;
 --replace_column 8 # 9 #
 SHOW EVENTS;
-# 
-# End of tests
-#
+
+--echo
+--echo #
+--echo # Bug#12394306: the sever may crash if mysql.event is corrupted
+--echo #
+
+--echo
+CREATE EVENT ev1 ON SCHEDULE EVERY 5 HOUR DO SELECT 5;
+ALTER EVENT ev1 ON SCHEDULE EVERY 8 HOUR DO SELECT 8;
+
+--echo
+CREATE TABLE event_original LIKE mysql.event;
+INSERT INTO event_original SELECT * FROM mysql.event;
+
+--echo
+ALTER TABLE mysql.event MODIFY modified CHAR(1);
+
+--echo
+--error ER_CANNOT_LOAD_FROM_TABLE
+SHOW EVENTS;
+
+--echo
+--error ER_CANNOT_LOAD_FROM_TABLE
+SELECT event_name, created, last_altered FROM information_schema.events;
+
+--echo
+--error ER_EVENT_OPEN_TABLE_FAILED
+CREATE EVENT ev2 ON SCHEDULE EVERY 5 HOUR DO SELECT 5;
+
+--echo
+--error ER_EVENT_OPEN_TABLE_FAILED
+ALTER EVENT ev1 ON SCHEDULE EVERY 9 HOUR DO SELECT 9;
+
+--echo
+DROP TABLE mysql.event;
+RENAME TABLE event_original TO mysql.event;
+
+--echo
+DROP EVENT ev1;
+
+--echo
+SHOW EVENTS;
+
+
+--echo
+--echo # 
+--echo # End of tests
+--echo #
 
 let $wait_condition=
   select count(*) = 0 from information_schema.processlist

=== modified file 'sql/event_data_objects.cc'
--- a/sql/event_data_objects.cc	2010-06-11 12:52:06 +0000
+++ b/sql/event_data_objects.cc	2011-04-25 15:22:23 +0000
@@ -617,6 +617,12 @@ Event_timed::load_from_row(THD *thd, TAB
   definer_host.str= strmake_root(&mem_root, ptr + 1,  len);
   definer_host.length= len;
 
+  if (table->field[ET_FIELD_CREATED]->type() != MYSQL_TYPE_TIMESTAMP ||
+      table->field[ET_FIELD_MODIFIED]->type() != MYSQL_TYPE_TIMESTAMP)
+  {
+    DBUG_RETURN(TRUE);
+  }
+
   created= table->field[ET_FIELD_CREATED]->val_int();
   modified= table->field[ET_FIELD_MODIFIED]->val_int();
 

=== modified file 'sql/event_db_repository.cc'
--- a/sql/event_db_repository.cc	2011-03-21 16:02:47 +0000
+++ b/sql/event_db_repository.cc	2011-04-25 15:22:23 +0000
@@ -317,7 +317,13 @@ mysql_event_fill_row(THD *thd,
     */
   }
 
-  ((Field_timestamp *)fields[ET_FIELD_MODIFIED])->set_time();
+  if (fields[ET_FIELD_MODIFIED]->type() == MYSQL_TYPE_TIMESTAMP)
+    ((Field_timestamp *) fields[ET_FIELD_MODIFIED])->set_time();
+  else
+  {
+    my_error(ER_EVENT_OPEN_TABLE_FAILED, MYF(0));
+    DBUG_RETURN(TRUE);
+  }
 
   if (et->comment.str)
   {
@@ -671,7 +677,14 @@ Event_db_repository::create_event(THD *t
     goto end;
   }
 
-  ((Field_timestamp *)table->field[ET_FIELD_CREATED])->set_time();
+  if (table->field[ET_FIELD_CREATED]->type() == MYSQL_TYPE_TIMESTAMP)
+    ((Field_timestamp *) table->field[ET_FIELD_CREATED])->set_time();
+  else
+  {
+    my_error(ER_EVENT_OPEN_TABLE_FAILED, MYF(0));
+    DBUG_RETURN(TRUE);
+  }
+
 
   /*
     mysql_event_fill_row() calls my_error() in case of error so no need to


Attachment: [text/bzr-bundle] bzr/alexander.nozdrin@oracle.com-20110425152223-9nf4y70nbj8nvfzy.bundle
Thread
bzr commit into mysql-5.1 branch (alexander.nozdrin:3670) Bug#12394306Alexander Nozdrin25 Apr
  • Re: bzr commit into mysql-5.1 branch (alexander.nozdrin:3670) Bug#12394306Davi Arnaut27 Apr