Bug #2347 mysql-test crashes when connecting, in test ctype_cp1251
Submitted: 11 Jan 2004 8:51 Modified: 12 Jan 2004 11:34
Reporter: Guilhem Bichot Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1 OS:
Assigned to: Alexander Barkov CPU Architecture:Any

[11 Jan 2004 8:51] Guilhem Bichot
Description:
Reference is my email
Re: Bootstrap of /home/autobuild/autobuild/bk-trees/mysql-4.1 failed
of 11 Jan 2004 17:37:01 +0100
mysqltest, mysql, mysqladmin all crash (segfault) when connecting to a mysqld
started with --default-character-set=cp1251

How to repeat:
see test failures.

Suggested fix:
Crash is in:

autobuild@build:~/autobuild/mysql-4.1.2-alpha-nightly-20040111-build/client> gdb ./mysql2
GNU gdb 5.2.1
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-suse-linux"...
(gdb) run  --socket=../mysql-test/var/tmp/master.sock
Starting program: /home/autobuild/autobuild/mysql-4.1.2-alpha-nightly-20040111-build/client/mysql2 --socket=../mysql-test/var/tmp/master.sock

Program received signal SIGSEGV, Segmentation fault.
0x400856d0 in get_internal_charset (cs_number=51, flags=0) at charset.c:543
543     charset.c: No such file or directory.
        in charset.c
Current language:  auto; currently c
(gdb) f
#0  0x400856d0 in get_internal_charset (cs_number=51, flags=0) at charset.c:543
543     in charset.c
(gdb) bt
#0  0x400856d0 in get_internal_charset (cs_number=51, flags=0) at charset.c:543
#1  0x4008572a in get_charset (cs_number=51, flags=0) at charset.c:557
#2  0x4009b3f9 in mysql_real_connect (mysql=0x80760c0, host=0x400a6a12 "localhost", user=0x400a68e5 "",
    passwd=0x400a68e5 "", db=0x0, port=3306, unix_socket=0x8077f30 "../mysql-test/var/tmp/master.sock",
    client_flag=66560) at client.c:1784
#3  0x08056196 in sql_real_connect (host=0x0, database=0x0, user=0x0, password=0x0, silent=0)
    at mysql.cc:2620
#4  0x08056276 in sql_connect (host=0x0, database=0x0, user=0x0, password=0x0, silent=0) at mysql.cc:2652
#5  0x08051dc7 in main (argc=2, argv=0x8077d78) at mysql.cc:365
#6  0x401757ee in __libc_start_main () from /lib/libc.so.6
(gdb) p cs_number
$1 = 51
(gdb) p all_charsets
$2 = {0x0, 0x400c32e0, 0x400c3fe0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8075da8, 0x0, 0x0, 0x0, 0x40155f40,
  0x401390e0, 0x0, 0x0, 0x0, 0x0, 0x4013b740, 0x400e4e00, 0x0, 0x0, 0x0, 0x0, 0x40100f80, 0x0, 0x0, 0x0,
  0x40128bc0, 0x0, 0x0, 0x400abfa0, 0x0, 0x400eab80, 0x400e5f80, 0x400eb660, 0x0 <repeats 11 times>,
  0x400ac200, 0x0 <repeats 15 times>, 0x400ac860, 0x0 <repeats 19 times>, 0x400eade0, 0x400c3540,
  0x400e5060, 0x401011e0, 0x40128e20, 0x40139340, 0x4013b9a0, 0x400eb8c0, 0x401561a0,
  0x0 <repeats 164 times>}
(gdb) p all_charsets[51]
$3 = (CHARSET_INFO *) 0x0

Here:
static CHARSET_INFO *get_internal_charset(uint cs_number, myf flags)
{
  char  buf[FN_REFLEN];
  CHARSET_INFO *cs;
  /*
    To make things thread safe we are not allowing other threads to interfere
    while we may changing the cs_info_table
  */
  pthread_mutex_lock(&THR_LOCK_charset);

  cs= all_charsets[cs_number];

  if (cs && !(cs->state & MY_CS_COMPILED) && !(cs->state & MY_CS_LOADED))
  {
     strxmov(get_charsets_dir(buf), cs->csname, ".xml", NullS);
     my_read_charset_file(buf,flags);
  }
  cs= (cs->state & MY_CS_AVAILABLE) ? cs : NULL;
  pthread_mutex_unlock(&THR_LOCK_charset);
  return cs;
}

as all_charsets[51] is 0, cs gets 0, and cs->state triggers segfault.
[12 Jan 2004 3:26] Alexander Barkov
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html