summaryrefslogtreecommitdiff
path: root/libmysql
diff options
context:
space:
mode:
authorunknown <jimw@mysql.com>2005-05-07 07:50:04 -0700
committerunknown <jimw@mysql.com>2005-05-07 07:50:04 -0700
commite584559febc18f045b74e1e13e58c88eba92c76a (patch)
treedf67399c9f4e6ac2b7144bf6efbdf78d5c6e5f59 /libmysql
parentce41e0de8132a95c98c16fe1b21c48cc5f366203 (diff)
downloadmariadb-git-e584559febc18f045b74e1e13e58c88eba92c76a.tar.gz
Backport fix for escaping multibyte characters. (Bug #9864)
libmysql/libmysql.c: Backport fix for escaping multibyte characters from 4.1
Diffstat (limited to 'libmysql')
-rw-r--r--libmysql/libmysql.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c
index 47f28e296b2..1e6a54455c4 100644
--- a/libmysql/libmysql.c
+++ b/libmysql/libmysql.c
@@ -3228,6 +3228,23 @@ mysql_sub_escape_string(CHARSET_INFO *charset_info, char *to,
from--;
continue;
}
+ /*
+ If the next character appears to begin a multi-byte character, we
+ escape that first byte of that apparent multi-byte character. (The
+ character just looks like a multi-byte character -- if it were actually
+ a multi-byte character, it would have been passed through in the test
+ above.)
+
+ Without this check, we can create a problem by converting an invalid
+ multi-byte character into a valid one. For example, 0xbf27 is not
+ a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
+ */
+ if (use_mb_flag && (l= my_mbcharlen(charset_info, *from)) > 1)
+ {
+ *to++= '\\';
+ *to++= *from;
+ continue;
+ }
#endif
switch (*from) {
case 0: /* Must be escaped for 'mysql' */
@@ -3300,6 +3317,23 @@ mysql_odbc_escape_string(MYSQL *mysql,
from--;
continue;
}
+ /*
+ If the next character appears to begin a multi-byte character, we
+ escape that first byte of that apparent multi-byte character. (The
+ character just looks like a multi-byte character -- if it were actually
+ a multi-byte character, it would have been passed through in the test
+ above.)
+
+ Without this check, we can create a problem by converting an invalid
+ multi-byte character into a valid one. For example, 0xbf27 is not
+ a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
+ */
+ if (use_mb_flag && (l= my_mbcharlen(mysql->charset, *from)) > 1)
+ {
+ *to++= '\\';
+ *to++= *from;
+ continue;
+ }
}
#endif
switch (*from) {