Bug #92214 mysql_options() makes mysql_real_connect() segfaults in _Z12set_my_errnoi()
Submitted: 28 Aug 2018 15:07 Modified: 29 Aug 2018 8:44
Reporter: Sebastien FLAESCH Email Updates:
Status: Unsupported Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S2 (Serious)
Version:8.0.12 OS:Red Hat (7.0)
Assigned to: CPU Architecture:POWER (ppc64)
Tags: crash mysql_options

[28 Aug 2018 15:07] Sebastien FLAESCH
Description:
When using mysql_options(), mysql_real_connect() segfaults in _Z12set_my_errnoi().

Tested with 8.0.11 and 8.0.12.

When compiling with debug options, we cannot reproduce the crash.

How to repeat:

>> conn = 0x1004fcc0

Program received signal SIGSEGV, Segmentation fault.
0x00003fffb7a932f8 in ._Z12set_my_errnoi () from /dbs/64bits/mys/8.0.12/lib/libmysqlclient.so.21
Missing separate debuginfos, use: debuginfo-install glibc-2.17-55.el7.ppc64 keyutils-libs-1.5.8-3.el7.ppc64 krb5-libs-1.11.3-49.el7.ppc64 libcom_err-1.42.9-4.el7.ppc64 libselinux-2.2.2-6.el7.ppc64 openssl-libs-1.0.1e-34.el7.ppc64 pcre-8.32-12.el7.ppc64 xz-libs-5.1.2-8alpha.el7.ppc64 zlib-1.2.7-13.el7.ppc64
(gdb) where
#0  0x00003fffb7a932f8 in ._Z12set_my_errnoi () from /dbs/64bits/mys/8.0.12/lib/libmysqlclient.so.21
#1  0x00003fffb7a90194 in ._Z7my_statPKcP4stati () from /dbs/64bits/mys/8.0.12/lib/libmysqlclient.so.21
#2  0x00003fffb7aa1d10 in ._ZL28search_default_file_with_extPFiPvPKcS1_S1_ES_S1_S1_S1_ib.constprop.59 ()
   from /dbs/64bits/mys/8.0.12/lib/libmysqlclient.so.21
#3  0x00003fffb7aa36b4 in ._Z22my_search_option_filesPKcPiPPPcPjPFiPvS0_S0_S0_ES6_PS0_bb ()
   from /dbs/64bits/mys/8.0.12/lib/libmysqlclient.so.21
#4  0x00003fffb7aa3a4c in .my_load_defaults () from /dbs/64bits/mys/8.0.12/lib/libmysqlclient.so.21
#5  0x00003fffb7a177b0 in .mysql_read_default_options () from /dbs/64bits/mys/8.0.12/lib/libmysqlclient.so.21
#6  0x00003fffb7a1f91c in .mysql_real_connect () from /dbs/64bits/mys/8.0.12/lib/libmysqlclient.so.21
#7  0x0000000010000b00 in .main ()
(gdb) b search_default_file_with_ext(int (*)(void*, char const*, char const*, char const*), void*, char const*, char const*, char const*, int, bool)
[29 Aug 2018 7:33] MySQL Verification Team
#  x86_64

rm -rf data/
bin/mysqld --initialize-insecure --basedir=$PWD --datadir=$PWD/data --log-error-verbosity=3
bin/mysqld --no-defaults --basedir=$PWD --datadir=$PWD/data --core-file --socket=/tmp/mysql_8012.sock --port=9999 --log-error=$PWD/data/log.err 2>&1 &

[umshastr@hod03]/export/umesh/server/source/bugs/src_build/92214/mysql-8.0.12-linux-glibc2.12-x86_64/bin: vi mystest.c
[umshastr@hod03]/export/umesh/server/source/bugs/src_build/92214/mysql-8.0.12-linux-glibc2.12-x86_64/bin: g++ mystest.c -Wall -m64 -O0 -g -o mystest `mysql_config --libs_r` `mysql_config --include`
mystest.c:4:6: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
 main() {
      ^
mystest.c: In function ‘int main()’:
mystest.c:7:19: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
    char *server = "localhost";
                   ^
mystest.c:8:17: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
    char *user = "root";
                 ^
mystest.c:9:21: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
    char *password = ""; /* set me first */
                     ^
mystest.c:10:21: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
    char *database = "mys80xpolka64b1";
                     ^

[umshastr@hod03]/export/umesh/server/source/bugs/src_build/92214/mysql-8.0.12-linux-glibc2.12-x86_64/bin: ldd ./mystest
        linux-vdso.so.1 =>  (0x00007fff33fd4000)
        libmysqlclient.so.21 => /export/umesh/server/source/bugs/src_build/92214/mysql-8.0.12-linux-glibc2.12-x86_64/lib/libmysqlclient.so.21 (0x00007f083f7bf000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f083f581000)
        librt.so.1 => /lib64/librt.so.1 (0x00007f083f379000)
        libssl.so.1.0.0 => /export/umesh/server/source/bugs/src_build/92214/mysql-8.0.12-linux-glibc2.12-x86_64/lib/libssl.so.1.0.0 (0x00007f083f109000)
        libcrypto.so.1.0.0 => /export/umesh/server/source/bugs/src_build/92214/mysql-8.0.12-linux-glibc2.12-x86_64/lib/libcrypto.so.1.0.0 (0x00007f083ecd1000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f083eacd000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f083e7c6000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f083e4c3000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f083e2ad000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f083deee000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f083ff12000)

[umshastr@hod03]/export/umesh/server/source/bugs/src_build/92214/mysql-8.0.12-linux-glibc2.12-x86_64/bin: ./mystest
>> conn = 0x6db2c0

 cat /etc/*release
Oracle Linux Server release 7.1
NAME="Oracle Linux Server"
VERSION="7.1"
ID="ol"
VERSION_ID="7.1"
PRETTY_NAME="Oracle Linux Server 7.1"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:7:1"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://bugzilla.oracle.com/"

ORACLE_BUGZILLA_PRODUCT="Oracle Linux 7"
ORACLE_BUGZILLA_PRODUCT_VERSION=7.1
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=7.1
Red Hat Enterprise Linux Server release 7.1 (Maipo)
Oracle Linux Server release 7.1

# Will check on other architecture and then inform reporter that the reported platform is "unsupported"
[29 Aug 2018 8:26] MySQL Verification Team
Hello Sebastien,

Thank you for the report.
Please note that POWER (ppc64) is not officially supported architecture which can also be confirmed from the supported platform list available at - https://www.mysql.com/support/supportedplatforms/database.html

Also, I quickly checked on OL7(x86_64) but not seeing any segfaults issues with the provided test case.

regards,
Umesh
[29 Aug 2018 8:44] Sebastien FLAESCH
Thanks you Umesh this clarifies the issue, I have overlooked supported platforms.
Seb