summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2020-05-06 13:19:35 +0400
committerAlexander Barkov <bar@mariadb.com>2020-05-06 13:19:35 +0400
commit8ad3c6154b90314980faf1cdd4c317c9bbf5f84c (patch)
treee2399c81f80f3a9f1d2ecfbd587e8b16709e8e39
parent7bcaa541aa1f298abf8e863566a19b3e9ec2f659 (diff)
downloadmariadb-git-8ad3c6154b90314980faf1cdd4c317c9bbf5f84c.tar.gz
MDEV-22130 SHOW WARNINGS will SIGSEGV 10.5 optimized build after setting CHARACTER_SET_RESULTS to NULL and running any invalid SQL | Binary_string::copy_printable_hhhh
The old code did not take into account that thd->variables.character_set_results can be NULL.
-rw-r--r--mysql-test/main/ctype_errors.result11
-rw-r--r--mysql-test/main/ctype_errors.test11
-rw-r--r--sql/protocol.cc2
3 files changed, 23 insertions, 1 deletions
diff --git a/mysql-test/main/ctype_errors.result b/mysql-test/main/ctype_errors.result
index 6f9e14a8942..9916fb7c9c4 100644
--- a/mysql-test/main/ctype_errors.result
+++ b/mysql-test/main/ctype_errors.result
@@ -49,3 +49,14 @@ ERROR 42000: \0423 \0432\0430\0441 \043E\0448\0438\0431\043A\0430 \0432 \0437\04
disconnect con1;
connection default;
End of 5.5 tests
+#
+# MDEV-22130 SHOW WARNINGS will SIGSEGV 10.5 optimized build after setting CHARACTER_SET_RESULTS to NULL and running any invalid SQL | Binary_string::copy_printable_hhhh
+#
+SET NAMES latin1;
+SET @@CHARACTER_SET_RESULTS=NULL;
+a;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'a' at line 1
+SHOW WARNINGS;
+Level Code Message
+Error 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'a' at line 1
+SET NAMES latin1;
diff --git a/mysql-test/main/ctype_errors.test b/mysql-test/main/ctype_errors.test
index b228a3b9f19..9ede9933ca7 100644
--- a/mysql-test/main/ctype_errors.test
+++ b/mysql-test/main/ctype_errors.test
@@ -58,3 +58,14 @@ disconnect con1;
connection default;
--echo End of 5.5 tests
+
+--echo #
+--echo # MDEV-22130 SHOW WARNINGS will SIGSEGV 10.5 optimized build after setting CHARACTER_SET_RESULTS to NULL and running any invalid SQL | Binary_string::copy_printable_hhhh
+--echo #
+
+SET NAMES latin1;
+SET @@CHARACTER_SET_RESULTS=NULL;
+--error ER_PARSE_ERROR
+a;
+SHOW WARNINGS;
+SET NAMES latin1;
diff --git a/sql/protocol.cc b/sql/protocol.cc
index 21efac46c52..1829294097d 100644
--- a/sql/protocol.cc
+++ b/sql/protocol.cc
@@ -1194,7 +1194,7 @@ bool Protocol::store_warning(const char *from, size_t length)
{
BinaryStringBuffer<MYSQL_ERRMSG_SIZE> tmp;
CHARSET_INFO *cs= thd->variables.character_set_results;
- if (cs == &my_charset_bin)
+ if (!cs || cs == &my_charset_bin)
cs= system_charset_info;
if (tmp.copy_printable_hhhh(cs, system_charset_info, from, length))
return net_store_data((const uchar*)"", 0);