List:Commits« Previous MessageNext Message »
From:Alfranio Correia Date:February 11 2009 3:39pm
Subject:bzr commit into mysql-5.1-bugteam branch (alfranio.correia:2768)
Bug#38174
View as plain text  
#At file:///home/acorreia/workspace.sun/repository.mysql/bzrwork/bug-38174/mysql-5.1-bugteam/ based on revid:matthias.leich@stripped

 2768 Alfranio Correia	2009-02-11
      BUG#38174 secure-file-priv breaks LOAD DATA INFILE replication in statement mode
      
      If secure-file-priv was set on slave, it became unable to execute
      LOAD DATA INFILE statements sent from master using mixed or
      statement-based replication.
      
      This patch fixes the issue by ignoring this security restriction
      and checking if the files are created and read by the slave in the
      --slave-load-tmpdir while executing the SQL Thread.
added:
  mysql-test/suite/rpl/r/rpl_bug38174.result
  mysql-test/suite/rpl/t/rpl_bug38174-slave.opt
  mysql-test/suite/rpl/t/rpl_bug38174.test
modified:
  sql/log_event.cc
  sql/log_event.h
  sql/sql_load.cc

per-file messages:
  sql/log_event.cc
    Replaced the string "SQL_LOAD-" by a macro PREFIX_SQL_LOAD.
  sql/log_event.h
    Defined a macro PREFIX_SQL_LOAD.
=== added file 'mysql-test/suite/rpl/r/rpl_bug38174.result'
--- a/mysql-test/suite/rpl/r/rpl_bug38174.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/r/rpl_bug38174.result	2009-02-11 15:39:04 +0000
@@ -0,0 +1,84 @@
+stop slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+reset master;
+reset slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+start slave;
+drop table if exists t1;
+stop slave;
+CREATE TABLE t1 (
+`pk` int(11) NOT NULL AUTO_INCREMENT,
+`int_nokey` int(11) NOT NULL,
+`int_key` int(11) NOT NULL,
+`date_key` date NOT NULL,
+`date_nokey` date NOT NULL,
+`time_key` time NOT NULL,
+`time_nokey` time NOT NULL,
+`datetime_key` datetime NOT NULL,
+`datetime_nokey` datetime NOT NULL,
+`varchar_key` varchar(1) NOT NULL,
+`varchar_nokey` varchar(1) NOT NULL,
+PRIMARY KEY (`pk`),
+KEY `int_key` (`int_key`),
+KEY `date_key` (`date_key`),
+KEY `time_key` (`time_key`),
+KEY `datetime_key` (`datetime_key`),
+KEY `varchar_key` (`varchar_key`)
+);
+INSERT INTO t1 VALUES (1,8,5,'0000-00-00','0000-00-00','10:37:38','10:37:38','0000-00-00 00:00:00','0000-00-00 00:00:00','p','p'),
+(2,1,6,'2005-12-23','2005-12-23','02:24:28','02:24:28','0000-00-00 00:00:00','0000-00-00 00:00:00','g','g'),
+(3,0,3,'2009-09-14','2009-09-14','00:00:00','00:00:00','2000-01-30 16:39:40','2000-01-30 16:39:40','q','q'),
+(4,1,4,'2002-12-03','2002-12-03','20:34:58','20:34:58','2009-10-28 09:46:21','2009-10-28 09:46:21','g','g'),
+(5,1,6,'2007-03-29','2007-03-29','15:49:00','15:49:00','0000-00-00 00:00:00','0000-00-00 00:00:00','m','m'),
+(6,4,0,'2002-12-04','2002-12-04','00:00:00','00:00:00','0000-00-00 00:00:00','0000-00-00 00:00:00','o','o'),
+(7,9,0,'2005-01-28','2005-01-28','00:00:00','00:00:00','2001-05-18 00:00:00','2001-05-18 00:00:00','w','w'),
+(8,6,0,'0000-00-00','0000-00-00','06:57:25','06:57:25','0000-00-00 00:00:00','0000-00-00 00:00:00','m','m'),
+(9,0,0,'0000-00-00','0000-00-00','00:00:00','00:00:00','0000-00-00 00:00:00','0000-00-00 00:00:00','z','z'),
+(10,4,6,'2006-08-15','2006-08-15','00:00:00','00:00:00','2002-04-12 14:44:25','2002-04-12 14:44:25','j','j'),
+(11,0,5,'2006-12-20','2006-12-20','10:13:53','10:13:53','2008-07-22 00:00:00','2008-07-22 00:00:00','y','y'),
+(12,9,7,'0000-00-00','0000-00-00','00:00:00','00:00:00','2004-07-05 00:00:00','2004-07-05 00:00:00','{','{'),
+(13,4,3,'2007-01-26','2007-01-26','23:00:51','23:00:51','2001-05-16 00:00:00','2001-05-16 00:00:00','f','f'),
+(14,7,0,'2004-03-27','2004-03-27','00:00:00','00:00:00','2005-01-24 03:30:37','2005-01-24 03:30:37','',''),
+(15,6,0,'2006-07-26','2006-07-26','18:43:57','18:43:57','0000-00-00 00:00:00','0000-00-00 00:00:00','{','{'),
+(16,0,6,'2000-01-14','2000-01-14','00:00:00','00:00:00','2000-09-21 00:00:00','2000-09-21 00:00:00','o','o'),
+(17,9,8,'0000-00-00','0000-00-00','21:15:08','21:15:08','0000-00-00 00:00:00','0000-00-00 00:00:00','a','a'),
+(18,2,0,'2004-10-27','2004-10-27','00:00:00','00:00:00','2004-03-24 22:13:43','2004-03-24 22:13:43','',''),
+(19,7,4,'0000-00-00','0000-00-00','08:38:27','08:38:27','2002-03-18 19:51:44','2002-03-18 19:51:44','t','t'),
+(20,5,3,'2008-03-07','2008-03-07','03:29:07','03:29:07','2007-12-01 18:44:44','2007-12-01 18:44:44','t','t'),
+(77,6,0,'2009-05-19','2009-05-19','14:56:44','14:56:44','2007-09-09 22:47:39','2007-09-09 22:47:39','',''),
+(35,6,3,'0000-00-00','0000-00-00','09:38:22','09:38:22','0000-00-00 00:00:00','0000-00-00 00:00:00','i','i'),
+(39,8,8,'0000-00-00','0000-00-00','10:25:31','10:25:31','2003-01-24 10:45:23','2003-01-24 10:45:23','',''),
+(29,5,6,'0000-00-00','0000-00-00','00:21:35','00:21:35','0000-00-00 00:00:00','0000-00-00 00:00:00','y','y'),
+(53,3,5,'0000-00-00','0000-00-00','00:00:00','00:00:00','2007-11-05 23:51:21','2007-11-05 23:51:21','p','p'),
+(60,0,2,'2009-09-11','2009-09-11','23:56:26','23:56:26','2003-12-24 04:28:32','2003-12-24 04:28:32','n','n'),
+(93,7,2,'2007-08-18','2007-08-18','00:00:00','00:00:00','2009-02-01 00:00:00','2009-02-01 00:00:00','y','y');
+SELECT * FROM t1 ORDER BY RAND () INTO OUTFILE "MYSQL_TEST_DIR/var/tmp/bug38174-1.test";
+drop table if exists t1;
+start slave;
+CREATE TABLE t1 (
+`pk` int(11) NOT NULL AUTO_INCREMENT,
+`int_nokey` int(11) NOT NULL,
+`int_key` int(11) NOT NULL,
+`date_key` date NOT NULL,
+`date_nokey` date NOT NULL,
+`time_key` time NOT NULL,
+`time_nokey` time NOT NULL,
+`datetime_key` datetime NOT NULL,
+`datetime_nokey` datetime NOT NULL,
+`varchar_key` varchar(1) NOT NULL,
+`varchar_nokey` varchar(1) NOT NULL,
+PRIMARY KEY (`pk`),
+KEY `int_key` (`int_key`),
+KEY `date_key` (`date_key`),
+KEY `time_key` (`time_key`),
+KEY `datetime_key` (`datetime_key`),
+KEY `varchar_key` (`varchar_key`)
+);
+LOAD DATA INFILE "MYSQL_TEST_DIR/var/tmp/bug38174-1.test" REPLACE INTO TABLE t1;
+select count(*) from t1;
+count(*)
+27
+select count(*) from t1;
+count(*)
+27
+drop table t1;

=== added file 'mysql-test/suite/rpl/t/rpl_bug38174-slave.opt'
--- a/mysql-test/suite/rpl/t/rpl_bug38174-slave.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_bug38174-slave.opt	2009-02-11 15:39:04 +0000
@@ -0,0 +1 @@
+--secure-file-priv=/tmp

=== added file 'mysql-test/suite/rpl/t/rpl_bug38174.test'
--- a/mysql-test/suite/rpl/t/rpl_bug38174.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_bug38174.test	2009-02-11 15:39:04 +0000
@@ -0,0 +1,147 @@
+##########################################################################
+# This test verifies if a slave is able to process a "LOAD DATA INFILE" 
+# event while the "--secure-file-priv" option is set.
+# 
+# The test is divided in five steps:
+#    1 - Stops replication
+#    2 - Creates a file in the master from which a table should be populate
+#    3 - Starts replication.
+#    4 - Creates a table and populates it through "LOAD DATA INFILE".
+#    5 - Compares the master and slave.
+##########################################################################
+
+##########################################################################
+#                       Configuring Environment
+##########################################################################
+source include/master-slave.inc;
+
+connection master;
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+##########################################################################
+#                       Stopping Replication
+##########################################################################
+connection slave;
+
+stop slave;
+source include/wait_for_slave_to_stop.inc;
+
+connection master;
+
+##########################################################################
+#                         Creating Load File
+##########################################################################
+CREATE TABLE t1 (
+  `pk` int(11) NOT NULL AUTO_INCREMENT,
+  `int_nokey` int(11) NOT NULL,
+  `int_key` int(11) NOT NULL,
+  `date_key` date NOT NULL,
+  `date_nokey` date NOT NULL,
+  `time_key` time NOT NULL,
+  `time_nokey` time NOT NULL,
+  `datetime_key` datetime NOT NULL,
+  `datetime_nokey` datetime NOT NULL,
+  `varchar_key` varchar(1) NOT NULL,
+  `varchar_nokey` varchar(1) NOT NULL,
+  PRIMARY KEY (`pk`),
+  KEY `int_key` (`int_key`),
+  KEY `date_key` (`date_key`),
+  KEY `time_key` (`time_key`),
+  KEY `datetime_key` (`datetime_key`),
+  KEY `varchar_key` (`varchar_key`)
+);
+
+INSERT INTO t1 VALUES (1,8,5,'0000-00-00','0000-00-00','10:37:38','10:37:38','0000-00-00 00:00:00','0000-00-00 00:00:00','p','p'),
+(2,1,6,'2005-12-23','2005-12-23','02:24:28','02:24:28','0000-00-00 00:00:00','0000-00-00 00:00:00','g','g'),
+(3,0,3,'2009-09-14','2009-09-14','00:00:00','00:00:00','2000-01-30 16:39:40','2000-01-30 16:39:40','q','q'),
+(4,1,4,'2002-12-03','2002-12-03','20:34:58','20:34:58','2009-10-28 09:46:21','2009-10-28 09:46:21','g','g'),
+(5,1,6,'2007-03-29','2007-03-29','15:49:00','15:49:00','0000-00-00 00:00:00','0000-00-00 00:00:00','m','m'),
+(6,4,0,'2002-12-04','2002-12-04','00:00:00','00:00:00','0000-00-00 00:00:00','0000-00-00 00:00:00','o','o'),
+(7,9,0,'2005-01-28','2005-01-28','00:00:00','00:00:00','2001-05-18 00:00:00','2001-05-18 00:00:00','w','w'),
+(8,6,0,'0000-00-00','0000-00-00','06:57:25','06:57:25','0000-00-00 00:00:00','0000-00-00 00:00:00','m','m'),
+(9,0,0,'0000-00-00','0000-00-00','00:00:00','00:00:00','0000-00-00 00:00:00','0000-00-00 00:00:00','z','z'),
+(10,4,6,'2006-08-15','2006-08-15','00:00:00','00:00:00','2002-04-12 14:44:25','2002-04-12 14:44:25','j','j'),
+(11,0,5,'2006-12-20','2006-12-20','10:13:53','10:13:53','2008-07-22 00:00:00','2008-07-22 00:00:00','y','y'),
+(12,9,7,'0000-00-00','0000-00-00','00:00:00','00:00:00','2004-07-05 00:00:00','2004-07-05 00:00:00','{','{'),
+(13,4,3,'2007-01-26','2007-01-26','23:00:51','23:00:51','2001-05-16 00:00:00','2001-05-16 00:00:00','f','f'),
+(14,7,0,'2004-03-27','2004-03-27','00:00:00','00:00:00','2005-01-24 03:30:37','2005-01-24 03:30:37','',''),
+(15,6,0,'2006-07-26','2006-07-26','18:43:57','18:43:57','0000-00-00 00:00:00','0000-00-00 00:00:00','{','{'),
+(16,0,6,'2000-01-14','2000-01-14','00:00:00','00:00:00','2000-09-21 00:00:00','2000-09-21 00:00:00','o','o'),
+(17,9,8,'0000-00-00','0000-00-00','21:15:08','21:15:08','0000-00-00 00:00:00','0000-00-00 00:00:00','a','a'),
+(18,2,0,'2004-10-27','2004-10-27','00:00:00','00:00:00','2004-03-24 22:13:43','2004-03-24 22:13:43','',''),
+(19,7,4,'0000-00-00','0000-00-00','08:38:27','08:38:27','2002-03-18 19:51:44','2002-03-18 19:51:44','t','t'),
+(20,5,3,'2008-03-07','2008-03-07','03:29:07','03:29:07','2007-12-01 18:44:44','2007-12-01 18:44:44','t','t'),
+(77,6,0,'2009-05-19','2009-05-19','14:56:44','14:56:44','2007-09-09 22:47:39','2007-09-09 22:47:39','',''),
+(35,6,3,'0000-00-00','0000-00-00','09:38:22','09:38:22','0000-00-00 00:00:00','0000-00-00 00:00:00','i','i'),
+(39,8,8,'0000-00-00','0000-00-00','10:25:31','10:25:31','2003-01-24 10:45:23','2003-01-24 10:45:23','',''),
+(29,5,6,'0000-00-00','0000-00-00','00:21:35','00:21:35','0000-00-00 00:00:00','0000-00-00 00:00:00','y','y'),
+(53,3,5,'0000-00-00','0000-00-00','00:00:00','00:00:00','2007-11-05 23:51:21','2007-11-05 23:51:21','p','p'),
+(60,0,2,'2009-09-11','2009-09-11','23:56:26','23:56:26','2003-12-24 04:28:32','2003-12-24 04:28:32','n','n'),
+(93,7,2,'2007-08-18','2007-08-18','00:00:00','00:00:00','2009-02-01 00:00:00','2009-02-01 00:00:00','y','y');
+
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+--eval SELECT * FROM t1 ORDER BY RAND () INTO OUTFILE "$MYSQL_TEST_DIR/var/tmp/bug38174-1.test"
+
+drop table if exists t1;
+##########################################################################
+#                       Starting Replication
+##########################################################################
+connection slave;
+
+start slave;
+source include/wait_for_slave_to_start.inc;
+
+connection master;
+
+##########################################################################
+#                Populating a table through "LOAD DATA INFILE"
+##########################################################################
+CREATE TABLE t1 (
+  `pk` int(11) NOT NULL AUTO_INCREMENT,
+  `int_nokey` int(11) NOT NULL,
+  `int_key` int(11) NOT NULL,
+  `date_key` date NOT NULL,
+  `date_nokey` date NOT NULL,
+  `time_key` time NOT NULL,
+  `time_nokey` time NOT NULL,
+  `datetime_key` datetime NOT NULL,
+  `datetime_nokey` datetime NOT NULL,
+  `varchar_key` varchar(1) NOT NULL,
+  `varchar_nokey` varchar(1) NOT NULL,
+  PRIMARY KEY (`pk`),
+  KEY `int_key` (`int_key`),
+  KEY `date_key` (`date_key`),
+  KEY `time_key` (`time_key`),
+  KEY `datetime_key` (`datetime_key`),
+  KEY `varchar_key` (`varchar_key`)
+);
+
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+--eval LOAD DATA INFILE "$MYSQL_TEST_DIR/var/tmp/bug38174-1.test" REPLACE INTO TABLE t1
+
+##########################################################################
+#                       Checking Consistency
+##########################################################################
+save_master_pos;
+connection slave;
+sync_with_master;
+
+connection master;
+select count(*) from t1;
+connection slave;
+select count(*) from t1;
+
+connection master;
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+--remove_file $MYSQL_TEST_DIR/var/tmp/bug38174-1.test
+
+##########################################################################
+#                          Clean up
+##########################################################################
+drop table t1;
+
+save_master_pos;
+connection slave;
+sync_with_master;

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2009-02-04 11:08:27 +0000
+++ b/sql/log_event.cc	2009-02-11 15:39:04 +0000
@@ -354,7 +354,7 @@ static char *slave_load_file_stem(char *
                                   int event_server_id, const char *ext)
 {
   char *res;
-  fn_format(buf,"SQL_LOAD-",slave_load_tmpdir, "", MY_UNPACK_FILENAME);
+  fn_format(buf,PREFIX_SQL_LOAD,slave_load_tmpdir, "", MY_UNPACK_FILENAME);
   to_unix_path(buf);
 
   buf = strend(buf);
@@ -393,7 +393,7 @@ static void cleanup_load_tmpdir()
      we cannot meet Start_log event in the middle of events from one 
      LOAD DATA.
   */
-  p= strmake(prefbuf, STRING_WITH_LEN("SQL_LOAD-"));
+  p= strmake(prefbuf, STRING_WITH_LEN(PREFIX_SQL_LOAD));
   p= int10_to_str(::server_id, p, 10);
   *(p++)= '-';
   *p= 0;

=== modified file 'sql/log_event.h'
--- a/sql/log_event.h	2009-01-23 12:22:05 +0000
+++ b/sql/log_event.h	2009-02-11 15:39:04 +0000
@@ -47,6 +47,8 @@
 #include "rpl_reporting.h"
 #endif
 
+#define PREFIX_SQL_LOAD "SQL_LOAD-"
+
 /**
    Either assert or return an error.
 

=== modified file 'sql/sql_load.cc'
--- a/sql/sql_load.cc	2008-09-17 12:54:50 +0000
+++ b/sql/sql_load.cc	2009-02-11 15:39:04 +0000
@@ -310,8 +310,24 @@ int mysql_load(THD *thd,sql_exchange *ex
 	is_fifo = 1;
 #endif
 
-      if (opt_secure_file_priv &&
-          strncmp(opt_secure_file_priv, name, strlen(opt_secure_file_priv)))
+      if (thd->slave_thread)
+      {
+#ifdef HAVE_REPLICATION
+        char buf[FN_REFLEN];
+        fn_format(buf, PREFIX_SQL_LOAD, slave_load_tmpdir, "",
+                  MY_PACK_FILENAME | MY_UNPACK_FILENAME |
+                  MY_RETURN_REAL_PATH);
+        to_unix_path(buf);
+
+        if (strncmp(buf, name, strlen(buf)))
+        {
+          my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--slave-load-tmpdir");
+          DBUG_RETURN(TRUE);
+        }
+#endif
+      }
+      else if (opt_secure_file_priv &&
+               strncmp(opt_secure_file_priv, name, strlen(opt_secure_file_priv)))
       {
         /* Read only allowed from within dir specified by secure_file_priv */
         my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");

Thread
bzr commit into mysql-5.1-bugteam branch (alfranio.correia:2768)Bug#38174Alfranio Correia11 Feb
  • Re: bzr commit into mysql-5.1-bugteam branch(alfranio.correia:2768) Bug#38174Sergei Golubchik11 Feb
    • Re: bzr commit into mysql-5.1-bugteam branch (alfranio.correia:2768)Bug#38174Alfranio Correia11 Feb
      • Re: bzr commit into mysql-5.1-bugteam branch(alfranio.correia:2768) Bug#38174Sergei Golubchik11 Feb
        • Re: bzr commit into mysql-5.1-bugteam branch (alfranio.correia:2768)Bug#38174Alfranio Correia12 Feb
  • Re: bzr commit into mysql-5.1-bugteam branch (alfranio.correia:2768)Bug#38174He Zhenxing12 Feb
    • Re: bzr commit into mysql-5.1-bugteam branch (alfranio.correia:2768)Bug#38174Alfranio Correia12 Feb
      • Re: bzr commit into mysql-5.1-bugteam branch(alfranio.correia:2768) Bug#38174Sergei Golubchik12 Feb
        • Re: bzr commit into mysql-5.1-bugteam branch (alfranio.correia:2768)Bug#38174He Zhenxing13 Feb
          • Re: bzr commit into mysql-5.1-bugteam branch (alfranio.correia:2768)Bug#38174Sergei Golubchik13 Feb
            • Re: bzr commit into mysql-5.1-bugteam branch (alfranio.correia:2768)Bug#38174He Zhenxing14 Feb