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.
This commit is contained in:
Alexander Barkov 2020-05-06 13:19:35 +04:00
commit 8ad3c6154b
3 changed files with 23 additions and 1 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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);