summaryrefslogtreecommitdiff
path: root/sql/sql_string.cc
diff options
context:
space:
mode:
authorunknown <knielsen@knielsen-hq.org>2012-08-24 10:06:16 +0200
committerunknown <knielsen@knielsen-hq.org>2012-08-24 10:06:16 +0200
commitcdeabcfd436c65e0a97e74b1722d0259ba907541 (patch)
tree5f3bbc9f42cb88a5615ab48a421472a17f56d030 /sql/sql_string.cc
parent34f2f8ea41726d98e50752ff3453ebde70912c35 (diff)
downloadmariadb-git-cdeabcfd436c65e0a97e74b1722d0259ba907541.tar.gz
MDEV-382: Incorrect quoting
Various places in the server replication code was incorrectly quoting strings, which could lead to incorrect SQL on the slave/mysqlbinlog.
Diffstat (limited to 'sql/sql_string.cc')
-rw-r--r--sql/sql_string.cc28
1 files changed, 18 insertions, 10 deletions
diff --git a/sql/sql_string.cc b/sql/sql_string.cc
index d56766f8994..6d81d6b16cb 100644
--- a/sql/sql_string.cc
+++ b/sql/sql_string.cc
@@ -1157,39 +1157,47 @@ outp:
-
-void String::print(String *str)
+/*
+ Append characters to a single-quoted string '...', escaping special
+ characters as necessary.
+ Does not add the enclosing quotes, this is left up to caller.
+*/
+void String::append_for_single_quote(const char *st, uint len)
{
- char *st= (char*)Ptr, *end= st+str_length;
+ const char *end= st+len;
for (; st < end; st++)
{
uchar c= *st;
switch (c)
{
case '\\':
- str->append(STRING_WITH_LEN("\\\\"));
+ append(STRING_WITH_LEN("\\\\"));
break;
case '\0':
- str->append(STRING_WITH_LEN("\\0"));
+ append(STRING_WITH_LEN("\\0"));
break;
case '\'':
- str->append(STRING_WITH_LEN("\\'"));
+ append(STRING_WITH_LEN("\\'"));
break;
case '\n':
- str->append(STRING_WITH_LEN("\\n"));
+ append(STRING_WITH_LEN("\\n"));
break;
case '\r':
- str->append(STRING_WITH_LEN("\\r"));
+ append(STRING_WITH_LEN("\\r"));
break;
case '\032': // Ctrl-Z
- str->append(STRING_WITH_LEN("\\Z"));
+ append(STRING_WITH_LEN("\\Z"));
break;
default:
- str->append(c);
+ append(c);
}
}
}
+void String::print(String *str)
+{
+ str->append_for_single_quote(Ptr, str_length);
+}
/*
Exchange state of this object and argument.