List:Commits« Previous MessageNext Message »
From:Guangbao Ni Date:April 2 2009 5:36pm
Subject:bzr commit into mysql-5.1-bugteam branch (gni:2835) Bug#42640
View as plain text  
#At file:///home/ngb/mysql/bzr/bugteam-5.1-bug42640/

 2835 Guangbao Ni	2009-04-02
      Bug #42640  mysqld crashes when unsafe statements are executed (STRICT_TRANS_TABLES mode)
      
      Mysql server crashes because unsafe statements warning is wrongly elevated to error,
      which is set the error status of Diagnostics_area of the thread in THD::binlog_query().
      
      Yet the caller believes that binary logging shouldn't touch the status, so it will 
      set the status also later by my_ok(), my_error() or my_message() seperately 
      according to the execution result of the statement or transaction.
      But the status of Diagnostics_area of the thread is allowed to set only once.
      
      
      Fixed by setting ER_BINLOG_UNSAFE_STATEMENT warning to NOTE level
      modified:
        mysql-test/suite/binlog/r/binlog_stm_ps.result
        mysql-test/suite/binlog/r/binlog_unsafe.result
        mysql-test/suite/binlog/t/binlog_unsafe.test
        sql/sql_class.cc

per-file messages:
  mysql-test/suite/binlog/r/binlog_stm_ps.result
    Change binlog_unsafe warning to note level
  mysql-test/suite/binlog/r/binlog_unsafe.result
    1) Test case result for unsafe statements to ensure mysql sever don't crash
    2) Changing Binlog unsafe warning level to note level
  mysql-test/suite/binlog/t/binlog_unsafe.test
    Test case for unsafe statements to ensure mysql sever don't crash
  sql/sql_class.cc
    To ensure the ER_BINLOG_UNSAFE_STATEMENT warning don't elevate to error 
    even though strict sql_mode.
    So the issuing ER_BINLOG_UNSAFE_STATEMENT warning is set NOTE level
=== modified file 'mysql-test/suite/binlog/r/binlog_stm_ps.result'
--- a/mysql-test/suite/binlog/r/binlog_stm_ps.result	2008-03-25 13:28:12 +0000
+++ b/mysql-test/suite/binlog/r/binlog_stm_ps.result	2009-04-02 17:34:58 +0000
@@ -11,7 +11,7 @@ prepare s from "insert into t1 select 10
 set @a=100;
 execute s using @a;
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 show binlog events from <binlog_start>;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	use `test`; create table t1 (a int)

=== modified file 'mysql-test/suite/binlog/r/binlog_unsafe.result'
--- a/mysql-test/suite/binlog/r/binlog_unsafe.result	2009-03-05 18:39:02 +0000
+++ b/mysql-test/suite/binlog/r/binlog_unsafe.result	2009-04-02 17:34:58 +0000
@@ -10,25 +10,25 @@ INSERT DELAYED INTO t1 VALUES (5);
 ---- Insert directly ----
 INSERT INTO t1 VALUES (@@global.sync_binlog);
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 INSERT INTO t1 VALUES (@@session.insert_id);
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 INSERT INTO t1 VALUES (@@global.auto_increment_increment);
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 INSERT INTO t2 SELECT UUID();
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 INSERT INTO t2 VALUES (@@session.sql_mode);
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 INSERT INTO t2 VALUES (@@global.init_slave);
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 INSERT INTO t2 VALUES (@@hostname);
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 ---- Insert from stored procedure ----
 CREATE PROCEDURE proc()
 BEGIN
@@ -42,13 +42,13 @@ INSERT INTO t2 VALUES (@@hostname);
 END|
 CALL proc();
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 ---- Insert from stored function ----
 CREATE FUNCTION func()
 RETURNS INT
@@ -66,13 +66,13 @@ SELECT func();
 func()
 0
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 ---- Insert from trigger ----
 CREATE TRIGGER trig
 BEFORE INSERT ON trigger_table
@@ -88,14 +88,14 @@ INSERT INTO t2 VALUES (@@hostname);
 END|
 INSERT INTO trigger_table VALUES ('bye.');
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 ---- Insert from prepared statement ----
 PREPARE p1 FROM 'INSERT INTO t1 VALUES (@@global.sync_binlog)';
 PREPARE p2 FROM 'INSERT INTO t1 VALUES (@@session.insert_id)';
@@ -106,25 +106,25 @@ PREPARE p6 FROM 'INSERT INTO t2 VALUES (
 PREPARE p7 FROM 'INSERT INTO t2 VALUES (@@hostname)';
 EXECUTE p1;
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 EXECUTE p2;
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 EXECUTE p3;
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 EXECUTE p4;
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 EXECUTE p5;
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 EXECUTE p6;
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 EXECUTE p7;
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 ---- Insert from nested call of triggers / functions / procedures ----
 CREATE PROCEDURE proc1()
 INSERT INTO trigger_table VALUES ('ha!')|
@@ -154,13 +154,13 @@ EXECUTE prep6;
 func5()
 0
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 ==== Variables that should *not* be unsafe ====
 INSERT INTO t1 VALUES (@@session.pseudo_thread_id);
 INSERT INTO t1 VALUES (@@session.pseudo_thread_id);
@@ -195,16 +195,16 @@ DROP TABLE t1, t2, t3, trigger_table, tr
 CREATE TABLE t1(a INT, b INT, KEY(a), PRIMARY KEY(b));
 INSERT INTO t1 SELECT * FROM t1 LIMIT 1;
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 REPLACE INTO t1 SELECT * FROM t1 LIMIT 1;
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 UPDATE t1 SET a=1 LIMIT 1;
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 DELETE FROM t1 LIMIT 1;
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 CREATE PROCEDURE p1()
 BEGIN
 INSERT INTO t1 SELECT * FROM t1 LIMIT 1;
@@ -214,10 +214,10 @@ DELETE FROM t1 LIMIT 1;
 END|
 CALL p1();
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 DROP PROCEDURE p1;
 DROP TABLE t1;
 DROP TABLE IF EXISTS t1;
@@ -225,7 +225,7 @@ CREATE TABLE t1 (a VARCHAR(100), b VARCH
 INSERT INTO t1 VALUES ('a','b');
 UPDATE t1 SET b = '%s%s%s%s%s%s%s%s%s%s%s%s%s%s' WHERE a = 'a' LIMIT 1;
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 DROP TABLE t1;
 DROP TABLE IF EXISTS t1, t2;
 CREATE TABLE t1(i INT PRIMARY KEY);
@@ -234,7 +234,7 @@ CREATE TABLE t3(i INT, ch CHAR(50));
 "Should issue message Statement is not safe to log in statement format."
 INSERT INTO t1 SELECT * FROM t2 LIMIT 1;
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 CREATE FUNCTION func6()
 RETURNS INT
 BEGIN
@@ -246,7 +246,7 @@ END|
 "Should issue message Statement is not safe to log in statement format only once"
 INSERT INTO t3 VALUES(func6(), UUID());
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 "Check whether SET @@SQL_LOG_BIN = 0/1 doesn't work in substatements"
 CREATE FUNCTION fun_check_log_bin() RETURNS INT
 BEGIN
@@ -259,7 +259,7 @@ SELECT fun_check_log_bin();
 fun_check_log_bin()
 100
 Warnings:
-Warning	1592	Statement is not safe to log in statement format.
+Note	1592	Statement is not safe to log in statement format.
 "SQL_LOG_BIN should be ON still"
 SHOW VARIABLES LIKE "SQL_LOG_BIN";
 Variable_name	Value
@@ -309,4 +309,22 @@ DROP FUNCTION func7;
 DROP TRIGGER  trig;
 DROP TABLE t1, t2, t3, trigger_table;
 set @@SESSION.SQL_LOG_BIN = @save_log_bin;
+SET @save_sql_mode = @@SESSION.SQL_MODE;
+SET @@SESSION.SQL_MODE = STRICT_ALL_TABLES;
+CREATE TABLE t1(i INT PRIMARY KEY);
+CREATE TABLE t2(i INT PRIMARY KEY);
+INSERT INTO t1 SELECT * FROM t2 LIMIT 1;
+Warnings:
+Note	1592	Statement is not safe to log in statement format.
+INSERT INTO t1 VALUES(@@global.sync_binlog);
+Warnings:
+Note	1592	Statement is not safe to log in statement format.
+UPDATE t1 SET i = 999 LIMIT 1;
+Warnings:
+Note	1592	Statement is not safe to log in statement format.
+DELETE FROM t1 LIMIT 1;
+Warnings:
+Note	1592	Statement is not safe to log in statement format.
+DROP TABLE t1, t2;
+SET @@SESSION.SQL_MODE = @save_sql_mode;
 "End of tests"

=== modified file 'mysql-test/suite/binlog/t/binlog_unsafe.test'
--- a/mysql-test/suite/binlog/t/binlog_unsafe.test	2009-03-05 18:39:02 +0000
+++ b/mysql-test/suite/binlog/t/binlog_unsafe.test	2009-04-02 17:34:58 +0000
@@ -46,6 +46,7 @@
 # BUG#34732: mysqlbinlog does not print default values for auto_increment variables
 # BUG#34768: nondeterministic INSERT using LIMIT logged in stmt mode if binlog_format=mixed
 # BUG#41980, SBL, INSERT .. SELECT .. LIMIT = ERROR, even when @@SQL_LOG_BIN is 0
+# BUG#42640: mysqld crashes when unsafe statements are executed (STRICT_TRANS_TABLES mode)
 #
 # ==== Related test cases ====
 #
@@ -369,4 +370,22 @@ DROP FUNCTION func7;
 DROP TRIGGER  trig;
 DROP TABLE t1, t2, t3, trigger_table;
 set @@SESSION.SQL_LOG_BIN = @save_log_bin;
+
+#
+# For BUG#42640: mysqld crashes when unsafe statements are executed (STRICT_TRANS_TABLES mode)
+#
+SET @save_sql_mode = @@SESSION.SQL_MODE;
+SET @@SESSION.SQL_MODE = STRICT_ALL_TABLES;
+
+CREATE TABLE t1(i INT PRIMARY KEY);
+CREATE TABLE t2(i INT PRIMARY KEY);
+
+INSERT INTO t1 SELECT * FROM t2 LIMIT 1;
+INSERT INTO t1 VALUES(@@global.sync_binlog);
+
+UPDATE t1 SET i = 999 LIMIT 1;
+DELETE FROM t1 LIMIT 1;
+
+DROP TABLE t1, t2;
+SET @@SESSION.SQL_MODE = @save_sql_mode;
 --echo "End of tests"

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2009-03-24 13:58:52 +0000
+++ b/sql/sql_class.cc	2009-04-02 17:34:58 +0000
@@ -3667,7 +3667,11 @@ int THD::binlog_query(THD::enum_binlog_q
   if (sql_log_bin_toplevel && lex->is_stmt_unsafe() &&
       variables.binlog_format == BINLOG_FORMAT_STMT)
   {
-    push_warning(this, MYSQL_ERROR::WARN_LEVEL_WARN,
+   /*
+     A warning can be elevated a error when STRICT sql mode.
+     But we don't want to elevate binlog warning to error here.
+   */
+    push_warning(this, MYSQL_ERROR::WARN_LEVEL_NOTE,
                  ER_BINLOG_UNSAFE_STATEMENT,
                  ER(ER_BINLOG_UNSAFE_STATEMENT));
     if (!(binlog_flags & BINLOG_FLAG_UNSAFE_STMT_PRINTED))

Thread
bzr commit into mysql-5.1-bugteam branch (gni:2835) Bug#42640Guangbao Ni2 Apr