#At file:///home/ngb/mysql/bzr/bug42640-5.1-bugteam/
2846 Guangbao Ni 2009-03-12
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 to clear the error wrongly set by binary logging, but keep the warning
message.
modified:
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_unsafe.result
Test case result for unsafe statements to ensure mysql sever don't crash
mysql-test/suite/binlog/t/binlog_unsafe.test
Test case for unsafe statements to ensure mysql sever don't crash
sql/sql_class.cc
the error status of the thread is cleared When a warning is elevated to an error
because of unsafe warning of binary log.
=== 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-03-12 18:10:28 +0000
@@ -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:
+Error 1592 Statement is not safe to log in statement format.
+INSERT INTO t1 VALUES(@@global.sync_binlog);
+Warnings:
+Error 1592 Statement is not safe to log in statement format.
+UPDATE t1 SET i = 999 LIMIT 1;
+Warnings:
+Error 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.
+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-03-12 18:10:28 +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-09 11:15:46 +0000
+++ b/sql/sql_class.cc 2009-03-12 18:10:28 +0000
@@ -3677,6 +3677,14 @@ int THD::binlog_query(THD::enum_binlog_q
MYSQL_ERRMSG_SIZE, query_arg);
binlog_flags|= BINLOG_FLAG_UNSAFE_STMT_PRINTED;
}
+ /*
+ A warning can be elevated a error when STRICT sql mode.
+ But we don't want to elevate binlog warning to error here.
+ */
+ if (is_error())
+ {
+ clear_error();
+ }
}
switch (qtype) {