summaryrefslogtreecommitdiff
path: root/sql/log.cc
diff options
context:
space:
mode:
authorRohit Kalhans <rohit.kalhans@oracle.com>2012-09-22 17:50:51 +0530
committerRohit Kalhans <rohit.kalhans@oracle.com>2012-09-22 17:50:51 +0530
commit5f003eca000167edc3601168029a7d86468e52a8 (patch)
tree4375fa1c0245bcb611e14ff982c80e6952f928e9 /sql/log.cc
parent600aa420d6bb17a2af779de11926ae1d3c122fd8 (diff)
downloadmariadb-git-5f003eca000167edc3601168029a7d86468e52a8.tar.gz
BUG#14548159: NUMEROUS CASES OF INCORRECT IDENTIFIER
QUOTING IN REPLICATION Problem: Misquoting or unquoted identifiers may lead to incorrect statements to be logged to the binary log. Fix: we use specialized functions to append quoted identifiers in the statements generated by the server.
Diffstat (limited to 'sql/log.cc')
-rw-r--r--sql/log.cc35
1 files changed, 24 insertions, 11 deletions
diff --git a/sql/log.cc b/sql/log.cc
index 7e0e90e28c0..93dd70b33c5 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -29,6 +29,7 @@
#include "rpl_filter.h"
#include "rpl_rli.h"
+#include "sql_show.h"
#include <my_dir.h>
#include <stdarg.h>
#include <m_ctype.h> // For test_if_number
@@ -1708,17 +1709,24 @@ static int binlog_savepoint_set(handlerton *hton, THD *thd, void *sv)
DBUG_ENTER("binlog_savepoint_set");
binlog_trans_log_savepos(thd, (my_off_t*) sv);
+
+ // buffer to store quoted identifier
+ char* buffer= (char *)my_malloc(sizeof("SAVEPOINT ")+ 1 + NAME_LEN * 2 + 2,
+ MYF(0));
+ String log_query(buffer, sizeof(buffer), system_charset_info);
+ log_query.length(0);
+
/* Write it to the binary log */
- String log_query;
- if (log_query.append(STRING_WITH_LEN("SAVEPOINT ")) ||
- log_query.append("`") ||
- log_query.append(thd->lex->ident.str, thd->lex->ident.length) ||
- log_query.append("`"))
+ if (log_query.append(STRING_WITH_LEN("SAVEPOINT ")))
DBUG_RETURN(1);
+ else
+ append_identifier(thd, &log_query, thd->lex->ident.str,
+ thd->lex->ident.length);
int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
Query_log_event qinfo(thd, log_query.c_ptr_safe(), log_query.length(),
TRUE, TRUE, errcode);
+ my_free(buffer, MYF(MY_WME));
DBUG_RETURN(mysql_bin_log.write(&qinfo));
}
@@ -1731,18 +1739,23 @@ static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv)
non-transactional table. Otherwise, truncate the binlog cache starting
from the SAVEPOINT command.
*/
- if (unlikely(trans_has_updated_non_trans_table(thd) ||
+ if (unlikely(trans_has_updated_non_trans_table(thd) ||
(thd->options & OPTION_KEEP_LOG)))
{
- String log_query;
- if (log_query.append(STRING_WITH_LEN("ROLLBACK TO ")) ||
- log_query.append("`") ||
- log_query.append(thd->lex->ident.str, thd->lex->ident.length) ||
- log_query.append("`"))
+ // buffer to store rollback query with quoted identifier
+ char* buffer= (char *)my_malloc(12 + 1 + NAME_LEN * 2 + 2, MYF(0));
+ String log_query(buffer, sizeof(buffer), system_charset_info);
+ log_query.length(0);
+
+ if (log_query.append(STRING_WITH_LEN("ROLLBACK TO ")))
DBUG_RETURN(1);
+ else
+ append_identifier(thd, &log_query, thd->lex->ident.str,
+ thd->lex->ident.length);
int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
Query_log_event qinfo(thd, log_query.c_ptr_safe(), log_query.length(),
TRUE, TRUE, errcode);
+ my_free(buffer, MYF(MY_WME));
DBUG_RETURN(mysql_bin_log.write(&qinfo));
}
binlog_trans_log_truncate(thd, *(my_off_t*)sv);