List:Commits« Previous MessageNext Message »
From:Jorgen Loland Date:August 11 2008 12:42pm
Subject:bzr push into mysql-6.0-backup branch (jorgen.loland:2681) Bug#34867
View as plain text  
 2681 Jorgen Loland	2008-08-11
      Bug#34867 - Backup: crash if altered view
            
      Old behavior: Server crash if a view was altered before backing 
      up the database.
                  
      New behavior: Backup command reports error.
                  
      Fix: A bug in si_objects.cc#do_serialize incorrectly returned
      'false' (success) when it failed to open a view. It now
      cleans up and returns 'true' (error) in this case.
modified:
  mysql-test/lib/mtr_report.pl
  mysql-test/r/backup_views.result
  mysql-test/t/backup_views.test
  sql/backup/stream_v1.c
  sql/si_objects.cc

=== modified file 'mysql-test/lib/mtr_report.pl'
--- a/mysql-test/lib/mtr_report.pl	2008-08-08 17:21:31 +0000
+++ b/mysql-test/lib/mtr_report.pl	2008-08-11 10:41:41 +0000
@@ -356,6 +356,7 @@ sub mtr_report_stats ($) {
 		($testname eq 'main.backup_views') and
 		(
 		  /Backup: Failed to add view/ or
+		  /Backup: Failed to obtain meta-data for view/ or
 		  /Restore: Could not restore view/
 		) or
  	 

=== modified file 'mysql-test/r/backup_views.result'
--- a/mysql-test/r/backup_views.result	2008-08-07 15:43:25 +0000
+++ b/mysql-test/r/backup_views.result	2008-08-11 10:41:41 +0000
@@ -566,7 +566,33 @@ ERROR HY000: Failed to add view `bup_db2
 *** EXIT Backup of database with missing view dependency
 
 
+*** ENTER Backup of database with altered view should report error, not crash server
+Test for bug#34867
+initializing test
+DROP DATABASE bup_db1;
+DROP DATABASE bup_db2;
+RESTORE FROM 'bup_objectview.bak';
+backup_id
+#
+USE bup_db1;
+CREATE VIEW alter1 AS SELECT 5;
+CREATE VIEW alter2 AS SELECT * FROM alter1;
+ALTER VIEW alter1 AS SELECT 6;
+
+Testing view selecting from altered view
+
+SELECT * FROM alter2;
+ERROR HY000: View 'bup_db1.alter2' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
+BACKUP DATABASE bup_db1 TO 'bup_alterview.bak';
+ERROR HY000: View 'bup_db1.alter2' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
+
+*** EXIT Backup of database with altered view
+
+
 ***  DROP bup_db1, bup_db2 DATABASE ****
 
+DROP TABLE bup_db1.t3;
+DROP TABLE bup_db1.t5;
+DROP TABLE bup_db2.t2;
 DROP DATABASE bup_db1;
 DROP DATABASE bup_db2;

=== modified file 'mysql-test/t/backup_views.test'
--- a/mysql-test/t/backup_views.test	2008-08-07 15:43:25 +0000
+++ b/mysql-test/t/backup_views.test	2008-08-11 10:41:41 +0000
@@ -327,6 +327,40 @@ BACKUP DATABASE bup_db2 TO 'bup_shouldfa
 --echo *** EXIT Backup of database with missing view dependency
 --echo
 
+--echo 
+--echo *** ENTER Backup of database with altered view should report error, not crash server
+--echo Test for bug#34867
+
+--echo initializing test
+
+# start with the backed up database
+DROP DATABASE bup_db1;
+DROP DATABASE bup_db2;
+
+replace_column 1 #;
+RESTORE FROM 'bup_objectview.bak';
+
+USE bup_db1;
+CREATE VIEW alter1 AS SELECT 5;
+CREATE VIEW alter2 AS SELECT * FROM alter1;
+ALTER VIEW alter1 AS SELECT 6;
+
+--echo
+--echo Testing view selecting from altered view
+--echo 
+
+--error ER_VIEW_INVALID
+SELECT * FROM alter2;
+
+#fails
+--error ER_VIEW_INVALID
+BACKUP DATABASE bup_db1 TO 'bup_alterview.bak';
+
+--echo 
+--echo *** EXIT Backup of database with altered view
+--echo 
+
+
 # Test cleanup section
 
 --echo
@@ -334,6 +368,9 @@ BACKUP DATABASE bup_db2 TO 'bup_shouldfa
 --echo
 
 
+DROP TABLE bup_db1.t3;
+DROP TABLE bup_db1.t5;
+DROP TABLE bup_db2.t2;
 DROP DATABASE bup_db1;
 DROP DATABASE bup_db2;
 
@@ -345,4 +382,6 @@ DROP DATABASE bup_db2;
 --remove_file $MYSQLTEST_VARDIR/master-data/bup_shouldfail1.bak
 --error 0,1
 --remove_file $MYSQLTEST_VARDIR/master-data/bup_shouldfail2.bak
+--error 0,1
+--remove_file $MYSQLTEST_VARDIR/master-data/bup_alterview.bak
 

=== modified file 'sql/backup/stream_v1.c'
--- a/sql/backup/stream_v1.c	2008-05-14 00:35:24 +0000
+++ b/sql/backup/stream_v1.c	2008-08-11 10:41:41 +0000
@@ -1555,14 +1555,25 @@ int bstream_wr_item_def(backup_stream *s
   blob data;
   int ret=BSTREAM_OK;
 
-  if (bcat_get_item_create_query(cat,item,&query) == BSTREAM_OK)
+  ret= bcat_get_item_create_query(cat,item,&query);
+  if (ret == BSTREAM_OK) 
     flags |= BSTREAM_FLAG_HAS_CREATE_STMT;
+  else if (ret == BSTREAM_ERROR) 
+    goto wr_error;
 
-  if (bcat_get_item_create_data(cat,item,&data) == BSTREAM_OK)
+  // bcat_get_item_create_data not in use yet. 
+  /*
+  ret= bcat_get_item_create_data(cat,item,&data);
+  if (ret == BSTREAM_OK)
     flags |= BSTREAM_FLAG_HAS_EXTRA_DATA;
-
+  else if (ret == BSTREAM_ERROR) 
+    goto wr_error;
+  */
+  
   ret= bstream_wr_meta_item(s,kind,flags,item);
-
+  if (ret == BSTREAM_ERROR) 
+    goto wr_error;
+  
   /* save create query and/or create data */
 
   if (flags & BSTREAM_FLAG_HAS_EXTRA_DATA)

=== modified file 'sql/si_objects.cc'
--- a/sql/si_objects.cc	2008-07-09 07:12:43 +0000
+++ b/sql/si_objects.cc	2008-08-11 10:41:41 +0000
@@ -1769,8 +1769,11 @@ bool TableObj::do_serialize(THD *thd, St
   /*
     Open the view and its base tables or views
   */
-  if (open_normal_and_derived_tables(thd, table_list, 0))
-    DBUG_RETURN(FALSE);
+  if (open_normal_and_derived_tables(thd, table_list, 0)) {
+    close_thread_tables(thd);
+    thd->lex->select_lex.table_list.empty();
+    DBUG_RETURN(TRUE);
+  }
 
   /*
     Setup view specific variables and settings

Thread
bzr push into mysql-6.0-backup branch (jorgen.loland:2681) Bug#34867Jorgen Loland11 Aug