Bug #74182 mysql --quick causes segmentation fault
Submitted: 1 Oct 2014 19:10 Modified: 23 Feb 2015 0:00
Reporter: Bill Karwin (Candidate Quality Contributor) (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.7.5 OS:Any
Assigned to: CPU Architecture:Any

[1 Oct 2014 19:10] Bill Karwin
Description:
It seems any command entered interactively in the mysql client with the --quick option causes the clause to crash with a segmentation fault.

Using --quick in batch mode does not crash.

I tried --quick because I was trying to see if there was an easy way to suppress writing to .mysql_history, to work around issues like Bug #72108. 

How to repeat:
$ mysql --quick
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.5-m15-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use test;
Segmentation fault

Suggested fix:
Provide a way to suppress writing interactive statements to .mysql_history without crashing.
[1 Oct 2014 23:57] Miguel Solorzano
Thank you for the bug report. Which exactly OS version are you using. I coudn't repeat on Windows with source compiled server:

C:\dbs>c:\dbs\5.7\bin\mysql -uroot --port=3570 --prompt="mysql 5.7 > "
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.7.6-m16 Source distribution

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql 5.7 > exit
Bye

C:\dbs>cd 5.6\bin

C:\dbs\5.6\bin>mysql -uroot --port=3570 --quick
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.6-m16 Source distribution

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use test
Database changed
mysql> show tables;
+------------------------------------------------------------------+
| Tables_in_test                                                   |
+------------------------------------------------------------------+
| at_symbol_test                                                   |
| pattern                                                          |
| source                                                           |
+------------------------------------------------------------------+
3 rows in set (0.00 sec)
[2 Oct 2014 1:08] Bill Karwin
I am using 64-bit CentOS Linux 6.5 on a VM running under VirtualBox.

$ uname -a
Linux ... 2.6.32-431.29.2.el6.x86_64 #1 SMP Tue Sep 9 21:36:05 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[2 Oct 2014 1:51] Miguel Solorzano
Thank you for the feedback. I was able to repeat with 5.7.5 released version. Will test source build.

>	mysql.exe!check_histignore(const char * string) Line 3132	C++
 	mysql.exe!add_filtered_history(const char * string) Line 3100	C++
 	mysql.exe!read_and_execute(bool interactive) Line 2284	C++
 	mysql.exe!main(int argc, char * * argv) Line 1393	C++
 	[External Code]
[2 Oct 2014 1:57] Miguel Solorzano
5.7.6 too affected:

my_bool check_histignore(const char *string)   <<< here
{
  int rc;

  LEX_STRING *tmp;

  DBUG_ENTER("check_histignore");

  for (tmp= histignore_patterns->begin();

>	mysql.exe!check_histignore(const char * string) Line 3132	C++
 	mysql.exe!read_and_execute(bool interactive) Line 2283	C++
 	mysql.exe!main(int argc, char * * argv) Line 1393	C++
 	[External Code]
[2 Oct 2014 2:15] Bill Karwin
I just noticed in my initial description, I wrote that this issue caused the "clause" to crash. I meant to write that it caused the "client" to crash.

I blame autocorrect.
[24 Dec 2014 20:08] Shane Bester
+1 I was about to file this myself, but found this bug report instead!  the issue is histignore things aren't initialized in quick/html/xml mode..

(gdb) bt
#0  in Prealloced_array<st_mysql_lex_string, 16ul, true>::begin (this=0x0) at /home/sbester/git/mysql-trunk/include/prealloced_array.h:174
#1  in check_histignore (string=0x51c3a40 "select 1;") at /home/sbester/git/mysql-trunk/client/mysql.cc:3147
#2  in add_filtered_history (string=0x51c3a40 "select 1;") at /home/sbester/git/mysql-trunk/client/mysql.cc:3115
#3  in add_line (buffer=..., line=0x51c3a40 "select 1;", line_length=9, in_string=0xffefffce7 "", ml_comment=0xffefffce6, truncated=false) at /home/sbester/git/mysql-trunk/client/mysql.cc:2475
#4  in read_and_execute (interactive=true) at /home/sbester/git/mysql-trunk/client/mysql.cc:2301
#5   in main (argc=7, argv=0x51573e0) at /home/sbester/git/mysql-trunk/client/mysql.cc:1392
(gdb) f 1
#1  0x0000000000411712 in check_histignore (string=0x51c3a40 "select 1;") at /home/sbester/git/mysql-trunk/client/mysql.cc:3147
3147      for (tmp= histignore_patterns->begin();
(gdb) p histignore_patterns
$4 = (Histignore_patterns *) 0x0
(gdb)
[24 Dec 2014 20:09] Shane Bester
Same as: Bug 19974879 - SEGMENTATION FAULT IN MYSQL CLIENT WHEN STARTED WITH --XML
[23 Feb 2015 0:00] Paul Dubois
Noted in 5.7.7, 5.8.0 changelogs.

The mysql client could exit prematurely when invoked with the --quick
option.