Bug #104584 Freshly built mysql client crashes in libedit/terminal.c
Submitted: 10 Aug 2021 14:27 Modified: 11 Aug 2021 14:59
Reporter: Kaige Ye (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Compiling Severity:S1 (Critical)
Version:5.7.35 OS:Ubuntu (20.04)
Assigned to: CPU Architecture:x86
Tags: regression

[10 Aug 2021 14:27] Kaige Ye
Description:
The issue was already reported for version 8 and closed.
https://bugs.mysql.com/bug.php?id=92046

The last comment in the report above says "Fixed in 5.7.30, 8.0.20 by this change", but with latest code whose version is 5.7.35, the issue is still there.

I encountered the same problem like Boris Ulasevich said, I didn't cleanup when cmake abort because libncurses5-dev is missing.

How to repeat:
apt remove libncurses5-dev

git clone https://github.com/mysql/mysql-server.git
cd mysql-server ; git checkout 5.7; mkdir bld ; cd bld
cmake .. -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/home/ubuntu/my_boost

apt install libncurses5-dev

make && make install
mysqld --initialize; mysqld &
mysql -uroot -p

Segmentation fault
[11 Aug 2021 12:56] MySQL Verification Team
Hello Kaige Ye,

Thank you for the report and feedback.
I tried to reproduce your issue on identical box but not seeing any issues. I'll be shortly joining the activity log for your reference.
Is there anything I'm missing here? I did remove libncurses5-dev just before cmake but didn't complain etc. Thank you.

regards,
Umesh
[11 Aug 2021 12:57] MySQL Verification Team
MySQL Server 5.7.35 build details

Attachment: 104584_5.7.35_src.build (application/octet-stream, text), 1.86 MiB.

[11 Aug 2021 13:30] Kaige Ye
I'm sorry, I forgot to mention that maybe you need to run `apt autoremove` or `apt purge libncurses5-dev` after `apt remove libncurses5-dev`. Because from the build log you provided, I didn't see the build failure at the first time, but I expected it to be fail because libncurses5-dev is missing. It seems like some header files were still there if you didn't run those commands after `apt autoremove libncurses5-dev`.

Or you can try another way, start a fresh Ubuntu box, confirm that no libncurses5-dev installed, and build from source directly. cmake will exits with missing dependencies messages, just install those dependencies and re-run cmake until cmake succeed, NEVER cleanup cmake directory. Build with make, the output mysql client will be the buggy one. If you compare the cmake generated config file with the correct one, you will find they are different with `HAVE_TERM_H`.
[11 Aug 2021 13:39] MySQL Verification Team
No problems, I'll give it a try and come back to you if still having issues in reproducing. Thank you.

regards,
Umesh
[11 Aug 2021 14:00] Kaige Ye
Below is what I did in my box, I just stopped before make because it takes time, but I can confirm that if `HAVE_TERM_H` is undefined, the output mysql client must cause a SIGSEGV. 

ubuntu@vm:~/repo/mysql-server-57/bld_debug$ cd ..
ubuntu@vm:~/repo/mysql-server-57$ mkdir sigsegv
ubuntu@vm:~/repo/mysql-server-57$ cd sigsegv/
ubuntu@vm:~/repo/mysql-server-57/sigsegv$ sudo apt remove libncurses5-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
  libncurses-dev
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
  libncurses5-dev
0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded.
After this operation, 6,144 B disk space will be freed.
Do you want to continue? [Y/n]
(Reading database ... 120450 files and directories currently installed.)
Removing libncurses5-dev:amd64 (6.2-0ubuntu2) ...
ubuntu@vm:~/repo/mysql-server-57/sigsegv$ sudo apt autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  libncurses-dev
0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded.
After this operation, 2,397 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 120449 files and directories currently installed.)
Removing libncurses-dev:amd64 (6.2-0ubuntu2) ...
Processing triggers for man-db (2.9.1-1) ...
ubuntu@vm:~/repo/mysql-server-57/sigsegv$ sudo apt purge libncurses5-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'libncurses5-dev' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
ubuntu@vm:~/repo/mysql-server-57/sigsegv$
ubuntu@vm:~/repo/mysql-server-57/sigsegv$ cmake .. -DCMAKE_BUILD_TYPE=Debug
CMake Deprecation Warning at CMakeLists.txt:35 (CMAKE_POLICY):
...
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:71 (MESSAGE):
  Curses library not found.  Please install appropriate package,

      remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
ubuntu@vm:~/repo/mysql-server-57/sigsegv$ sudo apt install libncurses5-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libncurses-dev
Suggested packages:
  ncurses-doc
The following NEW packages will be installed:
  libncurses-dev libncurses5-dev
0 upgraded, 2 newly installed, 0 to remove and 2 not upgraded.
Need to get 340 kB of archives.
After this operation, 2,403 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://mirrors.ustc.edu.cn/ubuntu focal/main amd64 libncurses-dev amd64 6.2-0ubuntu2 [339 kB]
Get:2 http://mirrors.ustc.edu.cn/ubuntu focal/main amd64 libncurses5-dev amd64 6.2-0ubuntu2 [976 B]
Fetched 340 kB in 1s (346 kB/s)
Selecting previously unselected package libncurses-dev:amd64.
(Reading database ... 120360 files and directories currently installed.)
Preparing to unpack .../libncurses-dev_6.2-0ubuntu2_amd64.deb ...
Unpacking libncurses-dev:amd64 (6.2-0ubuntu2) ...
Selecting previously unselected package libncurses5-dev:amd64.
Preparing to unpack .../libncurses5-dev_6.2-0ubuntu2_amd64.deb ...
Unpacking libncurses5-dev:amd64 (6.2-0ubuntu2) ...
Setting up libncurses-dev:amd64 (6.2-0ubuntu2) ...
Setting up libncurses5-dev:amd64 (6.2-0ubuntu2) ...
Processing triggers for man-db (2.9.1-1) ...
ubuntu@vm:~/repo/mysql-server-57/sigsegv$ cmake .. -DCMAKE_BUILD_TYPE=Debug
CMake Deprecation Warning at CMakeLists.txt:35 (CMAKE_POLICY):
...
-- CMAKE_SHARED_LINKER_FLAGS
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/repo/mysql-server-57/sigsegv
ubuntu@vm:~/repo/mysql-server-57/sigsegv$ grep -rn HAVE_TERM_H .
./include/config.h:63:/* #undef HAVE_TERM_H */
./include/my_config.h:63:/* #undef HAVE_TERM_H */
./CMakeCache.txt:2098:HAVE_TERM_H:INTERNAL=
./CMakeFiles/CMakeError.log:374:Building C object CMakeFiles/cmTC_20086.dir/HAVE_TERM_H.c.o
./CMakeFiles/CMakeError.log:375:/usr/bin/cc   -fPIC -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing     -o CMakeFiles/cmTC_20086.dir/HAVE_TERM_H.c.o   -c /home/ubuntu/repo/mysql-server-57/sigsegv/CMakeFiles/CheckIncludeFiles/HAVE_TERM_H.c
./CMakeFiles/CMakeError.log:376:/home/ubuntu/repo/mysql-server-57/sigsegv/CMakeFiles/CheckIncludeFiles/HAVE_TERM_H.c:2:10: fatal error: curses.h: No such file or directory
./CMakeFiles/CMakeError.log:380:make[1]: *** [CMakeFiles/cmTC_20086.dir/build.make:66: CMakeFiles/cmTC_20086.dir/HAVE_TERM_H.c.o] Error 1
ubuntu@vm:~/repo/mysql-server-57/sigsegv$ grep -rn HAVE_TERM_H ../bld_debug/
^C
ubuntu@vm:~/repo/mysql-server-57/sigsegv$ grep -rn HAVE_TERM_H ../bld_debug/include/
../bld_debug/include/config.h:63:#define HAVE_TERM_H 1
../bld_debug/include/my_config.h:63:#define HAVE_TERM_H 1
ubuntu@vm:~/repo/mysql-server-57/sigsegv$
ubuntu@vm:~/repo/mysql-server-57/sigsegv$ grep -rn HAVE_TERM_H ../bld_debug/CMakeCache.txt
2098:HAVE_TERM_H:INTERNAL=1
ubuntu@vm:~/repo/mysql-server-57/sigsegv$
[11 Aug 2021 14:59] MySQL Verification Team
Thank you for the details, I'm able to reproduce now.

umshastr@umshastr-ubuntu:~/Downloads/mysql-5.7.35/bld$ bin/mysql -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
umshastr@umshastr-ubuntu:~/Downloads/mysql-5.7.35/bld$ bin/mysql -uroot
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
umshastr@umshastr-ubuntu:~/Downloads/mysql-5.7.35/bld$ bin/mysql -uroot -S /tmp/mysql_ushastry.sock 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.35 Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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

Segmentation fault (core dumped)