Description:
Hi team,
When shutting down or restarting a MySQL instance, the mysql client got a segmentation fault in status command.
```
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:19002' (111)
Client characterset: utf8mb4
Program received signal SIGSEGV, Segmentation fault.
0x0000000000412d5f in com_status (buffer=<optimized out>, line=<optimized out>)
at ../../mysql-8.0.41/client/mysql.cc:4917
warning: Source file is more recent than executable.
4917 tee_fprintf(stdout, "Server characterset:\t%s\n", mysql.charset->csname);
(gdb) p mysql.charset
$1 = (CHARSET_INFO *) 0x0
```
How to repeat:
- Running status commands after the restart
restart;
status;
status;
status;
Suggested fix:
This is a patch for mysql-8.0.42. It will exit when the mysql.charset is null.
diff --git a/client/mysql.cc b/client/mysql.cc
index 108e3184b5a..56179fff4c3 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -4914,6 +4914,8 @@ static int com_status(String *buffer [[maybe_unused]],
} else {
/* Probably pre-4.1 server */
tee_fprintf(stdout, "Client characterset:\t%s\n", charset_info->csname);
+ if (!mysql.charset)
+ return EXIT_FAILURE;
tee_fprintf(stdout, "Server characterset:\t%s\n", mysql.charset->csname);
}