From c579bce3497bdf700b19bfe50a75e641330646d3 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Mon, 25 Mar 2013 16:45:24 +0200 Subject: Patch by Ian Good for MDEV-4319: mysqlbinlog output ambiguous escaping The output of mysqlbinlog (with "-v --base64-output=DECODE-ROWS" flags) can not always be read or parsed correctly when string columns contain single-quotes or backslash characters. The fix for this bug is to escape single-quote and backslash characters on output, so that the result is both more readable and more easily parse-able. Note that this is just for comments, so it doesn't affect the replication. sql/log_event.cc: Escape \ and ' properly for mysqlbin user comments. --- sql/log_event.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sql/log_event.cc b/sql/log_event.cc index 44ff00f9b25..331b86ca29f 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1804,6 +1804,7 @@ void Log_event::print_header(IO_CACHE* file, /** Prints a quoted string to io cache. Control characters are displayed as hex sequence, e.g. \x00 + Single-quote and backslash characters are escaped with a \ @param[in] file IO cache @param[in] prt Pointer to string @@ -1819,6 +1820,10 @@ my_b_write_quoted(IO_CACHE *file, const uchar *ptr, uint length) { if (*s > 0x1F) my_b_write(file, s, 1); + else if (*s == '\'') + my_b_write(file, "\\'", 2); + else if (*s == '\\') + my_b_write(file, "\\\\", 2); else { uchar hex[10]; -- cgit v1.2.1