Bug #356 mysql client seg faults on "connect" command with incorrect database name
Submitted: 1 May 2003 8:16 Modified: 27 May 2003 2:52
Reporter: Harrison Fisk Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:4.0.12 OS:Windows (Windows 2000)
Assigned to: CPU Architecture:Any

[1 May 2003 8:16] Harrison Fisk
Description:
If you use the connect command from within the mysql client, which fails to connect for some reason, ie. an incorrect database name, while having your mysql prompt set to include \h which is the hostname, then it will cause the client to seg fault and popup a little box saying that it has generated errors and needs to be shutdown.

It appears to crash on Unix as well.

How to repeat:
shell> mysql --no-defaults --prompt="\h~>\_"
localhost~> connect adsfasfd
ERROR 1049: Unknown database 'adsfasfd'
Segmentation fault (core dumped)

This assumes that adsfasfd isn't a real database.

Suggested fix:
I am guessing that the hostname inside of mysql is getting set to something incorrect if the mysql client fails to reconnect.  Either that or the prompt display should check if it is connected and change the hostname to something saying it isn't connected.
[1 May 2003 9:57] MySQL Verification Team
Fixed.

Patch:
===== client/mysql.cc 1.135 vs edited =====
*** /tmp/mysql.cc-1.135-19786   Wed Apr 23 21:46:45 2003
--- edited/client/mysql.cc      Thu May  1 19:56:40 2003
***************
*** 2593,2598 ****
--- 2593,2600 ----
  static const char* construct_prompt()
  {
    //erase the old prompt
+   if (!mysql_get_host_info(&mysql))
+     return  processed_prompt.ptr();
    processed_prompt.free();
    //get the date struct
    time_t  lclock = time(NULL);
[27 May 2003 2:52] Michael Widenius
Thank you for your bug report. This issue has been fixed in the latest
development tree for that product. You can find more information about
accessing our development trees at 
    http://www.mysql.com/doc/en/Installing_source_tree.html

We have now fixed this a bit differently in the 4.0 source tree:

If the client is not connected to the server, one will get 'not_connected' in the prompt for variables that are server dependent.

Fix will be in 4.0.14